public IList<ItemFlowPlanDetail> ConvertOrderDmdToItemFlowPlanDetail(ItemFlowPlan itemFlowPlan, IList<OrderLocationTransaction> orderLocTransList)
        {
            IList<ItemFlowPlanDetail> itemFlowPlanDetailList = new List<ItemFlowPlanDetail>();
            List<DateTime> dateTimeList = this.CollectDateList(orderLocTransList);
            if (dateTimeList.Count > 0)
            {
                foreach (DateTime date in dateTimeList)
                {
                    ItemFlowPlanDetail itemFlowPlanDetail = new ItemFlowPlanDetail();
                    itemFlowPlanDetail.ItemFlowPlan = itemFlowPlan;
                    itemFlowPlanDetail.ReqDate = date;
                    itemFlowPlanDetail.OrderRemainQty = 0;
                    foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
                    {
                        if (DateTime.Compare(date, orderLocTrans.OrderDetail.OrderHead.WindowTime.Date) == 0)
                        {
                            itemFlowPlanDetail.OrderRemainQty += orderLocTrans.RemainQty;
                            ItemFlowPlanTrack itemFlowPlanTrack = new ItemFlowPlanTrack();
                            itemFlowPlanTrack.ItemFlowPlanDetail = itemFlowPlanDetail;
                            itemFlowPlanTrack.OrderLocationTransaction = orderLocTrans;
                            //itemFlowPlanTrack.DemandQty = orderLocTrans.RemainQty;
                            itemFlowPlanDetail.AddItemFlowPlanTrack(itemFlowPlanTrack);
                        }
                    }

                    if (itemFlowPlanDetail.OrderRemainQty > 0)
                    {
                        itemFlowPlanDetailList.Add(itemFlowPlanDetail);
                    }
                }
            }

            return itemFlowPlanDetailList;
        }
        public IList<ItemFlowPlanDetail> GetItemFlowPlanDetailView(ItemFlowPlan itemFlowPlan, IList<ItemFlowPlanDetail> itemFlowPlanDetailList, bool computePlanQty)
        {
            if (itemFlowPlan.PlanType == BusinessConstants.CODE_MASTER_PLAN_TYPE_VALUE_DMDSCHEDULE)
            {
                if (itemFlowPlanDetailList != null && itemFlowPlanDetailList.Count > 0)
                {
                    foreach (ItemFlowPlanDetail itemFlowPlanDetail in itemFlowPlanDetailList)
                    {
                        DateTime startWinTime = itemFlowPlanDetail.ReqDate.Date;
                        DateTime endWinTime = this.GetDmdEndTime(itemFlowPlanDetail, itemFlowPlanDetailList);

                        IList<OrderLocationTransaction> orderLocTransList = new List<OrderLocationTransaction>();
                        if (itemFlowPlanDetailList.IndexOf(itemFlowPlanDetail) == itemFlowPlanDetailList.Count - 1)
                        {
                            orderLocTransList = this.GetOpenOrderLocTransInByFlow(itemFlowPlan.Flow.Code, itemFlowPlan.FlowDetail.Item.Code, startWinTime, null);
                        }
                        else
                        {
                            orderLocTransList = this.GetOpenOrderLocTransInByFlow(itemFlowPlan.Flow.Code, itemFlowPlan.FlowDetail.Item.Code, startWinTime, endWinTime);
                        }

                        this.RefreshItemFlowPlanDetail(itemFlowPlanDetail, orderLocTransList);
                    }

                    if (DateTime.Compare(DateTime.Now.Date, itemFlowPlanDetailList[0].ReqDate) < 0)
                    {
                        IList<OrderLocationTransaction> orderLocTransList = this.GetOpenOrderLocTransInByFlow(itemFlowPlan.Flow.Code, itemFlowPlan.FlowDetail.Item.Code, DateTime.Now.Date, itemFlowPlanDetailList[0].ReqDate);
                        IList<ItemFlowPlanDetail> orderDemandList = this.ConvertOrderDmdToItemFlowPlanDetail(itemFlowPlan, orderLocTransList);
                        foreach (ItemFlowPlanDetail ifpd in itemFlowPlanDetailList)
                        {
                            orderDemandList.Add(ifpd);
                        }
                        itemFlowPlanDetailList = orderDemandList;
                    }
                }
                else
                {
                    IList<OrderLocationTransaction> orderLocTransList = this.GetOpenOrderLocTransInByFlow(itemFlowPlan.Flow.Code, itemFlowPlan.FlowDetail.Item.Code, DateTime.Now.Date, null);
                    itemFlowPlanDetailList = this.ConvertOrderDmdToItemFlowPlanDetail(itemFlowPlan, orderLocTransList);
                }
            }
            else if (itemFlowPlan.PlanType == BusinessConstants.CODE_MASTER_PLAN_TYPE_VALUE_MPS)
            {
                decimal PAB = this.GetDmdStartPAB(WorkCalendarMgrE.GetDayShiftStart(DateTime.Now, itemFlowPlan.Flow.PartyTo.Code), "", itemFlowPlan.FlowDetail.Item.Code);
                //itemFlowPlan.PAB = PAB;

                DateTime maxDate = DateTime.Now.Date;
                if (itemFlowPlanDetailList != null && itemFlowPlanDetailList.Count > 0)
                {
                    maxDate = itemFlowPlanDetailList[itemFlowPlanDetailList.Count - 1].ReqDate;
                }
                IList<OrderLocationTransaction> orderLocTransList = this.GetOpenOrderLocTransInByFlow(itemFlowPlan.Flow.Code, itemFlowPlan.FlowDetail.Item.Code, DateTime.Now.Date, null);
                if (orderLocTransList != null && orderLocTransList.Count > 0)
                {
                    DateTime maxWinTime = orderLocTransList[orderLocTransList.Count - 1].OrderDetail.OrderHead.WindowTime;
                    maxWinTime = WorkCalendarMgrE.GetDayShiftStart(maxWinTime, itemFlowPlan.Flow.PartyTo.Code);
                    if (DateTime.Compare(maxDate, maxWinTime) < 0)
                    {
                        maxDate = maxWinTime;
                    }
                }

                DateTime date = DateTime.Now.Date;
                while (date <= maxDate)
                {
                    ItemFlowPlanDetail itemFlowPlanDetail = new ItemFlowPlanDetail();
                    itemFlowPlanDetail.ItemFlowPlan = itemFlowPlan;
                    itemFlowPlanDetail.GrossDemand = 0;
                    itemFlowPlanDetail.OrderRemainQty = 0;
                    itemFlowPlanDetail.PlanQty = 0;

                    foreach (ItemFlowPlanDetail ifpd in itemFlowPlanDetailList)
                    {
                        if (DateTime.Compare(ifpd.ReqDate, date) == 0)
                        {
                            itemFlowPlanDetail = ifpd;
                            break;
                        }
                    }

                    foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
                    {
                        DateTime winTime = orderLocTrans.OrderDetail.OrderHead.WindowTime;
                        if (DateTime.Compare(date, winTime) <= 0 && DateTime.Compare(date.AddDays(1), winTime) > 0)
                        {
                            ItemFlowPlanTrack itemFlowPlanTrack = new ItemFlowPlanTrack();
                            itemFlowPlanTrack.ItemFlowPlanDetail = itemFlowPlanDetail;
                            itemFlowPlanTrack.OrderLocationTransaction = orderLocTrans;
                            //itemFlowPlanTrack.DemandQty = orderLocTrans.RemainQty;
                            itemFlowPlanDetail.AddItemFlowPlanTrack(itemFlowPlanTrack);
                        }
                    }

                    date = date.AddDays(1);
                }
            }

            itemFlowPlanDetailList = this.PlanningAndScheduling(itemFlowPlanDetailList, itemFlowPlan, computePlanQty);
            return itemFlowPlanDetailList;
        }
        private void RefreshItemFlowPlanDetail(ItemFlowPlanDetail itemFlowPlanDetail, IList<OrderLocationTransaction> orderLocTransList)
        {
            decimal inputOrderDmd = 0;
            if (orderLocTransList != null && orderLocTransList.Count > 0)
            {
                foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
                {
                    if (orderLocTrans.RemainQty > 0)
                    {
                        inputOrderDmd += orderLocTrans.RemainQty;

                        ItemFlowPlanTrack itemFlowPlanTrack = new ItemFlowPlanTrack();
                        itemFlowPlanTrack.ItemFlowPlanDetail = itemFlowPlanDetail;
                        itemFlowPlanTrack.OrderLocationTransaction = orderLocTrans;
                        //itemFlowPlanTrack.DemandQty = orderLocTrans.RemainQty;
                        itemFlowPlanDetail.AddItemFlowPlanTrack(itemFlowPlanTrack);
                    }
                }
            }

            itemFlowPlanDetail.OrderRemainQty = inputOrderDmd;
        }