public void TestGetHeadList() { using (ShimsContext.Create()) { //模拟返回结果 ShimFilialeSao.GetAllFiliale = () => new List <FilialeInfo> { new FilialeInfo { ID = new Guid("1E677868-AE98-4932-B4DB-0000020DC859"), Rank = (int)FilialeRank.Head }, new FilialeInfo { ID = new Guid("2E677868-AE98-4932-B4DB-0000020DC859"), Rank = (int)FilialeRank.Partial }, new FilialeInfo { ID = new Guid("3E677868-AE98-4932-B4DB-0000020DC859"), Rank = (int)FilialeRank.Child } }; var result = FilialeManager.GetHeadList(); Assert.IsNotNull(result); } }
// 采购中 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 + ");"); } }
/// <summary>计算采购单为采购中(分配采购公司) /// </summary> /// <param name="purchasingId">采购单Id</param> public void PurchaseInProcess(Guid purchasingId) { //获取采购单信息 var purchasingInfo = _purchasing.GetPurchasingById(purchasingId); //获取此采购单供应商绑定我方公司 var filialeIds = _companyCussent.GetCompanyBindingFiliale(purchasingInfo.CompanyID); //获取供应商信息(是否必开票) var cinfo = _companyCussent.GetCompanyCussent(purchasingInfo.CompanyID); //获取当前采购单供应商当前年月分配的具体采购额度(含剩余额度) var dateTime = DateTime.Now; IList <ProcurementTicketLimitInfo> ptlList = _procurementTicketLimitDal.GetProcurementTicketLimitDetailByCompanyId(purchasingInfo.CompanyID, dateTime.Year, dateTime.Month); //获取采购单商品分组金额集合 var goodsAmountList = _purchasing.GetGoodsAmountList(purchasingInfo.PurchasingID); //采购单商品总金额 var goodsSumAmount = goodsAmountList.Sum(ent => ent.AmountPrice); //采购单分组商品集合 IList <PurchasingGoodsSplitInfo> purchasingGoodsSplitList = new List <PurchasingGoodsSplitInfo>(); // 1.该采购单供应商没有绑定我方公司,则获取任意一总公司作为采购公司 if (filialeIds.Count == 0) { var filialeId = FilialeManager.GetHeadList().First(ent => ent.Name.Contains("可得")).ID; _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, filialeId, false); return; } // 1.未设置采购额度但已绑定我方公司(获取其中一家公司采购) if (ptlList.Count == 0 && filialeIds.Count > 0) { _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, filialeIds[0], false); return; } //1.只绑定一个采购公司 if (filialeIds.Count == 1 && ptlList.Count == 1) { if (cinfo.IsNeedInvoices) { _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, filialeIds[0], true); } else { var item = ptlList[0]; _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, filialeIds[0], goodsSumAmount <= item.SurplusLimit); } return; } //采购公司ID IList <Guid> filialeIdGuids = new List <Guid>(); foreach (var item in ptlList) { if (item.SurplusLimit > 0 || cinfo.IsNeedInvoices) { var info = new PurchasingGoodsSplitInfo { FilialeId = item.FilialeId, PurchasingLimit = item.SurplusLimit, TotalPurchasingLimit = item.TakerTicketLimit, IsElseFilialeId = false, PurchasingGoodsItemList = new List <PurchasingGoodsItemInfo>() }; purchasingGoodsSplitList.Add(info); } if (item.SurplusLimit < goodsSumAmount) { filialeIdGuids.Add(item.FilialeId); } } //所有采购公司剩余额度全部满足当前采购单,此采购单分配给剩余比例最大的采购公司 if (filialeIdGuids.Count == 0) { var maxItem = ptlList.OrderByDescending(ent => ent.SurplusProportion).ThenBy(ent => ent.SurplusLimit).ToList()[0]; _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, maxItem.FilialeId, true); return; } //如果剩余额度某家不满足当前采购单金额,此采购单分配给剩余比例最大且满足此采购单金额的采购公司 foreach (var item in ptlList.OrderByDescending(ent => ent.SurplusProportion).ThenBy(ent => ent.SurplusLimit).Where(item => item.SurplusLimit >= goodsSumAmount)) { _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, item.FilialeId, true); return; } //所有采购公司不满足当前采购单 if (filialeIdGuids.Count == ptlList.Count) { //如果采购单商品只有1个 if (goodsAmountList.Count == 1) { var item = ptlList.OrderByDescending(ent => ent.SurplusProportion).First(); _purchasing.PurchasingUpdate(purchasingInfo.PurchasingID, item.FilialeId, cinfo.IsNeedInvoices); return; } //循环采购商品从大到小 foreach (var gInfo in goodsAmountList.OrderByDescending(ent => ent.AmountPrice)) { //获取满足当前商品的采购公司,并将此商品添加到此采购公司 var tempgInfo = gInfo; var item = purchasingGoodsSplitList.Where(ent => ent.SurplusPurchasingLimit >= tempgInfo.AmountPrice).OrderBy(ent => ent.SurplusPurchasingLimit); if (item.Any()) { var temp = item.First(); var info = new PurchasingGoodsItemInfo { TotalGoodsAmount = gInfo.AmountPrice, IsOut = true, GoodsCode = gInfo.GoodsCode }; temp.PurchasingGoodsItemList.Add(info); } else { //如果是必开票 if (cinfo.IsNeedInvoices) { var item1 = purchasingGoodsSplitList.OrderByDescending(ent => ent.TotalPurchasingLimit).First(); var info1 = new PurchasingGoodsItemInfo { TotalGoodsAmount = gInfo.AmountPrice, IsOut = true, GoodsCode = gInfo.GoodsCode }; item1.PurchasingGoodsItemList.Add(info1); } else //非必开票 { //var item1 = purchasingGoodsSplitList.FirstOrDefault(ent => ent.IsElseFilialeId); //if (item1 != null) //{ // var info1 = new PurchasingGoodsItemInfo // { // TotalGoodsAmount = gInfo.AmountPrice, // IsOut = true, //cinfo.IsNeedInvoices // GoodsCode = gInfo.GoodsCode // }; // item1.PurchasingGoodsItemList.Add(info1); //} //else //{ //} //添加一条其他公司的记录 var info1 = new PurchasingGoodsItemInfo { TotalGoodsAmount = gInfo.AmountPrice, IsOut = false, GoodsCode = gInfo.GoodsCode }; IList <PurchasingGoodsItemInfo> items = new List <PurchasingGoodsItemInfo>(); items.Add(info1); //获取最大额度的采购公司 var maxItem = ptlList.OrderByDescending(ent => ent.TakerTicketLimit).First(); purchasingGoodsSplitList.Add(new PurchasingGoodsSplitInfo { FilialeId = maxItem.FilialeId, TotalPurchasingLimit = maxItem.TakerTicketLimit, PurchasingLimit = maxItem.SurplusLimit, IsElseFilialeId = true, PurchasingGoodsItemList = items }); } } } SplitPurchasing(purchasingId, purchasingGoodsSplitList); } }