示例#1
0
        private void GenPurchaseRccp(DateTime planVersion, CodeMaster.TimeUnit dateType, BusinessException businessException,
            IList<MrpFlowDetail> mrpFlowDetailList, IEnumerable<RccpTransGroup> rccpTransGroupList, DateTime snapTime, User user)
        {
            if(businessException.GetMessages().Where(p => p.MessageType == CodeMaster.MessageType.Error).Count() > 0)
            {
                //如果有错误,退出,不产生采购物料需求
                return;
            }

            var flowDetails = mrpFlowDetailList
                  .Where(p => p.Type == CodeMaster.OrderType.Procurement || p.Type == CodeMaster.OrderType.CustomerGoods
                   || p.Type == CodeMaster.OrderType.SubContract || p.Type == CodeMaster.OrderType.ScheduleLine);

            var purchasePlanList = new List<PurchasePlan>();
            var rccpTransGroupByIndexList = (from p in rccpTransGroupList
                                             group p by p.DateIndex into g
                                             select new
                                             {
                                                 DateIndex = g.Key,
                                                 List = g
                                             }).OrderBy(p => p.DateIndex).ToList();

            foreach(var rccpTransGroupByIndex in rccpTransGroupByIndexList)
            {
                DateTime windowTime = DateTime.Now;
                if(dateType == CodeMaster.TimeUnit.Week)
                {
                    windowTime = DateTimeHelper.GetWeekIndexDateFrom(rccpTransGroupByIndex.DateIndex);
                }
                else if(dateType == CodeMaster.TimeUnit.Month)
                {
                    windowTime = DateTime.Parse(rccpTransGroupByIndex.DateIndex + "-01");
                }
                var mrpFlowDetailDic = flowDetails.Where(p => p.StartDate <= windowTime && p.EndDate > windowTime)
                    .GroupBy(p => p.Item, (k, g) => new { k, g })
                    .ToDictionary(d => d.k, d => d.g);

                foreach(var groupRccpTrans in rccpTransGroupByIndex.List)
                {
                    var mrpFlowDetails = mrpFlowDetailDic.ValueOrDefault(groupRccpTrans.Item);
                    if(mrpFlowDetails != null)
                    {
                        foreach(var mrpFlowDetail in mrpFlowDetails)
                        {
                            var purchasePlan = new PurchasePlan();
                            purchasePlan.Item = groupRccpTrans.Item;
                            //purchasePlan.Sequence = mrpFlowDetail.Sequence;
                            purchasePlan.Flow = mrpFlowDetail.Flow;
                            purchasePlan.LocationTo = mrpFlowDetail.LocationTo;
                            purchasePlan.OrderType = mrpFlowDetail.Type;
                            purchasePlan.WindowTime = windowTime;
                            var leadDay = Utility.DateTimeHelper.TimeTranfer((decimal)mrpFlowDetail.LeadTime, CodeMaster.TimeUnit.Hour, CodeMaster.TimeUnit.Day);
                            if(dateType == CodeMaster.TimeUnit.Week)
                            {
                                purchasePlan.StartTime = purchasePlan.WindowTime.AddDays(3).AddDays(-leadDay);
                                purchasePlan.StartTime = Utility.DateTimeHelper.GetWeekStart(purchasePlan.StartTime);
                            }
                            else
                            {
                                purchasePlan.StartTime = purchasePlan.WindowTime.AddDays(15).AddDays(-leadDay);
                                purchasePlan.StartTime = Utility.DateTimeHelper.GetStartTime(CodeMaster.TimeUnit.Month, purchasePlan.StartTime);
                            }

                            purchasePlan.Qty = (mrpFlowDetail.MrpWeight / mrpFlowDetails.Sum(p => p.MrpWeight)) * groupRccpTrans.Qty;
                            purchasePlan.PlanQty = purchasePlan.Qty;
                            purchasePlan.DateType = dateType;
                            purchasePlan.PlanVersion = planVersion;
                            purchasePlanList.Add(purchasePlan);
                        }
                    }
                    else
                    {
                        if(groupRccpTrans.IsLastLevel)
                        {
                            businessException.AddMessage(new Message(CodeMaster.MessageType.Warning, "没有找到物料{0}的采购路线", groupRccpTrans.Item));
                        }
                    }
                }
            }

            string hql = string.Empty;
            if(dateType == CodeMaster.TimeUnit.Week)
            {
                hql = "from FlowStrategy where IsCheckMrpWeeklyPlan =? and Flow in(?";
            }
            else if(dateType == CodeMaster.TimeUnit.Month)
            {
                hql = "from FlowStrategy where IsCheckMrpMonthlyPlan =? and Flow in(?";
            }

            var flowStategys = this.genericMgr.FindAllIn<FlowStrategy>
                (hql, purchasePlanList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct(),
                new object[] { true });
            var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster>
             ("from FlowMaster where Code in(?", flowStategys.Select(p => p.Flow).Distinct())
             .GroupBy(p => p.Code, (k, g) => new { k, g.First().Description })
             .ToDictionary(d => d.k, d => d.Description);
            foreach(var flowStategy in flowStategys)
            {
                PurchasePlanMaster purchasePlanMaster = new PurchasePlanMaster();
                purchasePlanMaster.DateType = dateType;
                purchasePlanMaster.Flow = flowStategy.Flow;
                purchasePlanMaster.FlowDescription = flowMasterDic[flowStategy.Flow];
                purchasePlanMaster.PlanVersion = planVersion;
                purchasePlanMaster.SnapTime = snapTime;
                purchasePlanMaster.SourcePlanVersion = snapTime;

                purchasePlanMaster.CreateUserId = user.Id;
                purchasePlanMaster.CreateUserName = user.FullName;
                purchasePlanMaster.CreateDate = DateTime.Now;
                purchasePlanMaster.LastModifyUserId = user.Id;
                purchasePlanMaster.LastModifyUserName = user.FullName;
                purchasePlanMaster.LastModifyDate = DateTime.Now;

                this.genericMgr.Create(purchasePlanMaster);
            }

            purchasePlanList = purchasePlanList.Where(p => flowStategys.Select(q => q.Flow).Contains(p.Flow)).ToList();
            this.genericMgr.BulkInsert<PurchasePlan>(purchasePlanList);
        }
示例#2
0
        //
        #endregion

        #region _PurchasePlanMasterComboBox
        public ActionResult _PurchasePlanMasterComboBox(string controlName, string controlId, string selectedValue, bool? enable, int? dateType, string flow, bool? includeBlankOption, bool? isRelease, bool? isChange)
        {
            ViewBag.ControlName = controlName;
            ViewBag.ControlId = controlId;
            ViewBag.Enable = enable;
            ViewBag.DateType = dateType;
            ViewBag.Flow = flow;
            ViewBag.IncludeBlankOption = includeBlankOption;
            ViewBag.IsRelease = isRelease;
            ViewBag.isChange = isChange;
            IList<PurchasePlanMaster> planMasterList = new List<PurchasePlanMaster>();
            if (selectedValue != null && selectedValue.Trim() != string.Empty)
            {
                var planMaster = new PurchasePlanMaster();
                planMaster.PlanVersion = Convert.ToDateTime(selectedValue);
                planMasterList.Add(planMaster);
            }
            return PartialView(new SelectList(planMasterList, "PlanVersionShow", "PlanVersionShow", selectedValue != "" ? Convert.ToDateTime(selectedValue).ToString("yyyy-MM-dd HH:mm:ss") : selectedValue));
        }