Beispiel #1
0
        private void PrintInspect(Resolver resolver, string[] region)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(InspectOrder));

            criteria.Add(Expression.Eq("IsPrinted", false));
            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE));
            criteria.Add(Expression.In("Region", region));

            IList <InspectOrder> inspectOrderList = criteriaMgr.FindAll <InspectOrder>(criteria);

            List <ReceiptNote> receiptNotes = new List <ReceiptNote>();

            if (inspectOrderList != null && inspectOrderList.Count > 0)
            {
                foreach (InspectOrder inspectOrder in inspectOrderList)
                {
                    string newUrl = reportMgr.WriteToFile("InspectOrder.xls", inspectOrder.InspectNo);
                    inspectOrder.IsPrinted = true;//to be refactored
                    inspectOrderMgr.UpdateInspectOrder(inspectOrder);
                    ReceiptNote receiptNote = InspectOrder2ReceiptNote(inspectOrder);
                    receiptNote.PrintUrl = newUrl;
                    receiptNotes.Add(receiptNote);
                }
            }

            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange <ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
Beispiel #2
0
        public IList <Hu> CreateHu(IList <OrderDetail> orderDetailList, User user, string idMark, string packageType)
        {
            if (orderDetailList != null && orderDetailList.Count > 0)
            {
                IList <Hu> huList    = new List <Hu>();
                int?       huLotSize = null;
                foreach (OrderDetail orderDetail in orderDetailList)
                {
                    if (packageType == BusinessConstants.CODE_MASTER_PACKAGETYPE_INNER)
                    {
                        huLotSize = Convert.ToInt32(orderDetail.UnitCount);
                    }
                    else
                    {
                        huLotSize = orderDetail.HuLotSize;
                    }
                    string lotNo = orderDetail.HuLotNo != null && orderDetail.HuLotNo.Trim().Length != 0 ? orderDetail.HuLotNo.Trim() : LotNoHelper.GenerateLotNo(orderDetail.OrderHead.WindowTime);
                    IListHelper.AddRange <Hu>(huList,
                                              CreateHu(orderDetail.Item, orderDetail.OrderedQty, lotNo, orderDetail.Uom, orderDetail.UnitCount, huLotSize,
                                                       null, null, null, orderDetail.OrderHead.PartyFrom, BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1, user, orderDetail, null, orderDetail.ItemVersion, idMark, orderDetail.CustomerItemCode));
                }

                return(huList);
            }

            return(null);
        }
Beispiel #3
0
        private void PrintPickList(Resolver resolver, string[] region)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(PickList));

            criteria.Add(Expression.Eq("IsPrinted", false));
            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT));
            criteria.Add(Expression.In("PartyFrom.Code", region));

            IList <PickList> pickList = criteriaMgr.FindAll <PickList>(criteria);

            List <ReceiptNote> receiptNotes = new List <ReceiptNote>();

            if (pickList != null && pickList.Count > 0)
            {
                foreach (PickList pl in pickList)
                {
                    string newUrl = reportMgr.WriteToFile("PickList.xls", pl.PickListNo);
                    pl.IsPrinted = true;//to be refactored
                    pickListMgr.UpdatePickList(pl);
                    ReceiptNote receiptNote = PickList2ReceiptNote(pl);
                    receiptNote.PrintUrl = newUrl;
                    receiptNotes.Add(receiptNote);
                }
            }

            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange <ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
Beispiel #4
0
    private void BindData(bool includeBlank)
    {
        IList <StorageBin> binList = new List <StorageBin>();

        IListHelper.AddRange <StorageBin>(binList, this.StorageBinList);
        if (includeBlank)
        {
            StorageBin newBin = new StorageBin();
            newBin.IsBlank = true;
            binList.Add(newBin);
        }
        this.GV_List.DataSource = binList;
        this.GV_List.DataBind();
    }
        public IList <OrderLocationTransaction> GetOrderLocationTransaction(IList <string> orderNoList, string ioType)
        {
            IList <OrderLocationTransaction> orderLocTransList = new List <OrderLocationTransaction>();

            if (orderNoList != null && orderNoList.Count > 0)
            {
                foreach (string orderNo in orderNoList)
                {
                    IListHelper.AddRange <OrderLocationTransaction>(orderLocTransList,
                                                                    this.GetOrderLocationTransaction(orderNo, BusinessConstants.IO_TYPE_OUT));
                }
            }
            return(orderLocTransList);
        }
Beispiel #6
0
        //public void Execute(JobRunContext context)
        //{
        //    DetachedCriteria criteria = DetachedCriteria.For<OrderHead>();

        //    criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS));
        //    criteria.Add(Expression.Eq("IsAutoCreatePickList", true));

        //    //查找自动创建拣货单并且正在执行中的订单
        //    IList<OrderHead> orderHeadList = this.criteriaMgr.FindAll<OrderHead>(criteria);
        //    if (orderHeadList != null && orderHeadList.Count > 0)
        //    {
        //        foreach(OrderHead orderHead in orderHeadList)
        //        {
        //           GenertatePickList(orderHead);
        //        }
        //    }
        //}

        public void Execute(JobRunContext context)
        {
            DetachedCriteria criteria = DetachedCriteria.For <OrderHead>();

            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS));
            criteria.Add(Expression.Eq("IsAutoCreatePickList", true));
            criteria.Add(Expression.Eq("IsPickListCreated", false));

            //查找自动创建拣货单并且正在执行中的订单
            IList <OrderHead> orderHeadList = this.criteriaMgr.FindAll <OrderHead>(criteria);

            if (orderHeadList != null && orderHeadList.Count > 0)
            {
                string productLine = context.JobDataMap.GetStringValue("FlowCode");
                if (productLine != null && productLine != string.Empty)
                {
                    string[] productLineArray = productLine.Split('|');
                    foreach (string seperatedProductLineArray in productLineArray)
                    {
                        string[] plArray = seperatedProductLineArray.Split(',');

                        List <OrderHead> odList = new List <OrderHead>();

                        foreach (string pl in plArray)
                        {
                            IList <OrderHead> q = orderHeadList.Where(o => pl == o.Flow).ToList();
                            if (q != null && q.Count > 0)
                            {
                                IListHelper.AddRange <OrderHead>(odList, q);
                            }
                        }

                        if (odList != null && odList.Count > 0)
                        {
                            try
                            {
                                GenertatePickList(odList);
                            }
                            catch (Exception ex)
                            {
                                log.Error(ex);
                                this.criteriaMgr.FlushSession();
                                this.criteriaMgr.CleanSession();
                            }
                        }
                    }
                }
            }
        }
    private void BindData(bool includeBlank)
    {
        IList <Item> itemList = new List <Item>();

        IListHelper.AddRange <Item>(itemList, this.ItemList);
        if (includeBlank)
        {
            Item newItem = new Item();
            newItem.IsBlank = true;
            itemList.Add(newItem);
        }

        this.GV_List.DataSource = itemList;
        this.GV_List.DataBind();
    }
Beispiel #8
0
        public IList <Hu> CreateHu(OrderHead orderHead, User user)
        {
            if (orderHead.OrderDetails != null && orderHead.OrderDetails.Count > 0)
            {
                IList <Hu> huList = new List <Hu>();
                foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                {
                    IListHelper.AddRange <Hu>(huList,
                                              CreateHu(orderDetail.Item, orderDetail.OrderedQty, orderDetail.HuLotNo, orderDetail.Uom, orderDetail.UnitCount, orderDetail.HuLotSize,
                                                       null, null, null, orderDetail.OrderHead.PartyFrom, BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1, user, orderDetail, null, orderDetail.ItemVersion, null, orderDetail.CustomerItemCode));
                }

                return(huList);
            }

            return(null);
        }
        private void CreateRepack(Resolver resolver)
        {
            string[]           huIdArr      = resolver.Input.Split(',');
            List <ReceiptNote> receiptNotes = new List <ReceiptNote>();

            foreach (string huId in huIdArr)
            {
                try
                {
                    IList <RepackDetail> repackDetailList  = new List <RepackDetail>();
                    LocationLotDetail    locationLotDetail = locationLotDetailMgr.CheckLoadHuLocationLotDetail(huId);
                    RepackDetail         inRepackDetail    = new RepackDetail();
                    inRepackDetail.LocationLotDetail = locationLotDetail;
                    inRepackDetail.Hu     = locationLotDetail.Hu;
                    inRepackDetail.IOType = BusinessConstants.IO_TYPE_IN;
                    inRepackDetail.Qty    = inRepackDetail.Hu.Qty * inRepackDetail.Hu.UnitQty;
                    repackDetailList.Add(inRepackDetail);

                    RepackDetail outRepackDetail = new RepackDetail();
                    outRepackDetail.itemCode = inRepackDetail.Hu.Item.Code;
                    outRepackDetail.IOType   = BusinessConstants.IO_TYPE_OUT;
                    outRepackDetail.Qty      = inRepackDetail.Qty;
                    repackDetailList.Add(outRepackDetail);

                    Repack repack = repackMgr.CreateDevanning(repackDetailList, userMgr.CheckAndLoadUser(resolver.UserCode));

                    ReceiptNote receiptNote = Repack2ReceiptNote(repack);
                    receiptNotes.Add(receiptNote);
                }

                catch (Exception ex)
                {
                    continue;
                }
            }
            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange <ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
Beispiel #10
0
        private void PrintASN(Resolver resolver, string[] region)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(InProcessLocation));

            criteria.Add(Expression.Eq("IsPrinted", false));
            criteria.Add(Expression.Eq("NeedPrintAsn", true));
            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE));
            criteria.Add(Expression.Or(Expression.Eq("OrderType", BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION),
                                       Expression.Eq("OrderType", BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER)));
            criteria.Add(Expression.In("PartyFrom.Code", region));

            IList <InProcessLocation> inProcessLocationList = criteriaMgr.FindAll <InProcessLocation>(criteria);

            List <ReceiptNote> receiptNotes = new List <ReceiptNote>();

            if (inProcessLocationList != null && inProcessLocationList.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in inProcessLocationList)
                {
                    IList <object> list = new List <object>();
                    list.Add(inProcessLocation);
                    list.Add(inProcessLocation.InProcessLocationDetails);

                    string newUrl = reportMgr.WriteToFile(inProcessLocation.AsnTemplate, list);
                    inProcessLocation.IsPrinted = true;//to be refactored
                    inProcessLocationMgr.UpdateInProcessLocation(inProcessLocation);
                    ReceiptNote receiptNote = InProcessLocation2ReceiptNote(inProcessLocation);
                    receiptNote.PrintUrl = newUrl;
                    receiptNotes.Add(receiptNote);
                }
            }

            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange <ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
Beispiel #11
0
        private void PrintOrder(Resolver resolver, string[] region)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(OrderHead));

            criteria.Add(Expression.Eq("IsPrinted", false));
            criteria.Add(Expression.Eq("NeedPrintOrder", true));
            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS));
            criteria.Add(Expression.In("Type", new string[] { BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER, BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT }));
            criteria.Add(Expression.In("PartyFrom.Code", region));

            IList <OrderHead> orderList = criteriaMgr.FindAll <OrderHead>(criteria);

            List <ReceiptNote> receiptNotes = new List <ReceiptNote>();

            if (orderList != null && orderList.Count > 0)
            {
                foreach (OrderHead orderHead in orderList)
                {
                    IList <object> list = new List <object>();
                    list.Add(orderHead);
                    list.Add(orderHead.OrderDetails);

                    string newUrl = reportMgr.WriteToFile(orderHead.OrderTemplate, list);
                    orderHead.IsPrinted = true;//to be refactored
                    orderHeadMgr.UpdateOrderHead(orderHead);
                    ReceiptNote receiptNote = Order2ReceiptNote(orderHead);
                    receiptNote.PrintUrl = newUrl;
                    receiptNotes.Add(receiptNote);
                }
            }

            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange <ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
Beispiel #12
0
        private void PrintReceipt(Resolver resolver, string[] region)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(Receipt));

            criteria.Add(Expression.Eq("IsPrinted", false));
            criteria.Add(Expression.Eq("NeedPrint", true));
            criteria.Add(Expression.In("PartyTo.Code", region));

            IList <Receipt> receiptList = criteriaMgr.FindAll <Receipt>(criteria);

            List <ReceiptNote> receiptNotes = new List <ReceiptNote>();

            if (receiptList != null && receiptList.Count > 0)
            {
                foreach (Receipt receipt in receiptList)
                {
                    IList <object> list = new List <object>();
                    list.Add(receipt);
                    list.Add(receiptDetailMgr.SummarizeReceiptDetails(receipt.ReceiptDetails));

                    string newUrl = reportMgr.WriteToFile(receipt.ReceiptTemplate, list);
                    receipt.IsPrinted = true;//to be refactored
                    receiptMgr.UpdateReceipt(receipt);
                    ReceiptNote receiptNote = Receipt2ReceiptNote(receipt);
                    receiptNote.PrintUrl = newUrl;
                    receiptNotes.Add(receiptNote);
                }
            }

            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange <ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
Beispiel #13
0
        public IList <Hu> CreateHu(IList <FlowDetail> flowDetailList, User user, string idMark, string packageType)
        {
            if (flowDetailList != null && flowDetailList.Count > 0)
            {
                IList <Hu> huList    = new List <Hu>();
                int?       huLotSize = null;
                foreach (FlowDetail flowDetail in flowDetailList)
                {
                    Flow flow = flowDetail.Flow;
                    if (packageType == BusinessConstants.CODE_MASTER_PACKAGETYPE_INNER)
                    {
                        huLotSize = Convert.ToInt32(flowDetail.UnitCount);
                    }
                    else
                    {
                        huLotSize = flowDetail.HuLotSize;
                    }

                    if (flow.Type != BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_PRODUCTION)
                    {
                        IListHelper.AddRange <Hu>(huList,
                                                  CreateHu(flowDetail.Item, flowDetail.OrderedQty, flowDetail.HuLotNo, flowDetail.Uom, flowDetail.UnitCount, huLotSize,
                                                           null, null, null, flowDetail.Flow.PartyFrom, BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1, user, flowDetail, null, flowDetail.ItemVersion, idMark, flowDetail.CustomerItemCode));
                    }
                    else
                    {
                        IListHelper.AddRange <Hu>(huList,
                                                  CreateHu(flowDetail.Item, flowDetail.OrderedQty, flowDetail.HuLotNo, flowDetail.Uom, flowDetail.UnitCount, huLotSize,
                                                           null, null, null, flowDetail.Flow.PartyFrom, BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1, user, flowDetail, flowDetail.HuShiftCode, flowDetail.ItemVersion, idMark, flowDetail.CustomerItemCode));
                    }
                }

                return(huList);
            }

            return(null);
        }
Beispiel #14
0
    public void InitPageParameter(int id)
    {
        plannedBillView = this.ThePlannedBillViewMgr.LoadPlannedBillView(id);

        #region 查询PlannedBillView对应那些PlannedBill
        DetachedCriteria planBillCriteria = DetachedCriteria.For(typeof(PlannedBill));
        planBillCriteria.CreateAlias("Item", "item");
        planBillCriteria.CreateAlias("Uom", "uom");
        planBillCriteria.CreateAlias("BillAddress", "billAddr");

        planBillCriteria.Add(Expression.Or(Expression.IsNull("ActingQty"), Expression.Not(Expression.EqProperty("PlannedQty", "ActingQty"))));
        planBillCriteria.Add(Expression.Eq("item.Code", plannedBillView.Item.Code));
        planBillCriteria.Add(Expression.Eq("uom.Code", plannedBillView.Uom.Code));
        planBillCriteria.Add(Expression.Eq("UnitCount", plannedBillView.UnitCount));
        planBillCriteria.Add(Expression.Eq("billAddr.Code", plannedBillView.BillAddress.Code));

        IList <PlannedBill> plannedBillList = this.TheCriteriaMgr.FindAll <PlannedBill>(planBillCriteria);
        #endregion

        if (this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
        {
            #region 查询LoctionLotDetail并转换为CSInventoryDetail
            DetachedCriteria locLotDetCriteria = DetachedCriteria.For(typeof(LocationLotDetail));

            locLotDetCriteria.CreateAlias("Location", "loc");
            locLotDetCriteria.CreateAlias("StorageBin", "bin", NHibernate.SqlCommand.JoinType.LeftOuterJoin);
            locLotDetCriteria.CreateAlias("Item", "item");
            locLotDetCriteria.CreateAlias("PlannedBill", "pb");
            locLotDetCriteria.CreateAlias("pb.OrderHead", "od");
            //locLotDetCriteria.CreateAlias("Hu", "hu");

            locLotDetCriteria.SetProjection(
                Projections.ProjectionList()
                .Add(Projections.GroupProperty("loc.Code").As("LocationCode"))
                .Add(Projections.GroupProperty("loc.Name").As("LocationName"))
                .Add(Projections.GroupProperty("bin.Code").As("Bin"))
                //.Add(Projections.GroupProperty("hu.HuId"))
                .Add(Projections.GroupProperty("LotNo").As("LotNo"))
                .Add(Projections.GroupProperty("od.OrderNo").As("OrderNo"))
                .Add(Projections.GroupProperty("pb.ReceiptNo").As("ReceiptNo"))
                .Add(Projections.GroupProperty("pb.CreateDate").As("ReceiptDate"))
                .Add(Projections.GroupProperty("pb.SettleTerm").As("SettleTerm"))
                .Add(Projections.Sum("Qty").As("i"))
                .Add(Projections.GroupProperty("pb.UnitQty").As("j"))
                );

            locLotDetCriteria.Add(Expression.Not(Expression.Eq("Qty", decimal.Zero)));
            locLotDetCriteria.Add(Expression.Eq("IsConsignment", true));
            locLotDetCriteria.Add(Expression.InG("PlannedBill", plannedBillList));

            IList <CSInventoryDetail> csInventoryDetailList = ConvertLocLotDet2CSInventoryDetail(this.TheCriteriaMgr.FindAll(locLotDetCriteria));
            #endregion

            #region 查询IpDetail并转换为CSInventoryDetail
            DetachedCriteria ipDetCriteria = DetachedCriteria.For(typeof(InProcessLocationDetail));
            ipDetCriteria.CreateAlias("OrderLocationTransaction", "olt");
            ipDetCriteria.CreateAlias("InProcessLocation", "ip");
            ipDetCriteria.CreateAlias("PlannedBill", "pb");
            ipDetCriteria.CreateAlias("pb.OrderHead", "od");

            ipDetCriteria.SetProjection(
                Projections.ProjectionList()
                .Add(Projections.GroupProperty("ip.IpNo"))
                //.Add(Projections.GroupProperty("HuId"))
                .Add(Projections.GroupProperty("LotNo"))
                .Add(Projections.GroupProperty("od.OrderNo"))
                .Add(Projections.GroupProperty("pb.ReceiptNo"))
                .Add(Projections.GroupProperty("pb.CreateDate"))
                .Add(Projections.GroupProperty("pb.SettleTerm"))
                .Add(Projections.Sum("Qty"))
                .Add(Projections.GroupProperty("pb.UnitQty"))
                );

            ipDetCriteria.Add((Expression.Eq("ip.Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)));
            ipDetCriteria.Add(Expression.InG("PlannedBill", plannedBillList));
            IList <CSInventoryDetail> csInventoryDetailList2 = ConvertIpDet2CSInventoryDetail(this.TheCriteriaMgr.FindAll(ipDetCriteria));

            if (csInventoryDetailList2.Count > 0)
            {
                IListHelper.AddRange <CSInventoryDetail>(csInventoryDetailList, csInventoryDetailList2);

                IListHelper.Sort <CSInventoryDetail>(csInventoryDetailList, "ReceiptDate");
            }
            #endregion

            this.GV_List.DataSource = csInventoryDetailList;
            this.GV_List.DataBind();
        }
        else if (this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
        {
            DetachedCriteria planBillDetailCriteria = DetachedCriteria.For(typeof(PlannedBill));
            planBillDetailCriteria.CreateAlias("OrderHead", "od");

            planBillDetailCriteria.SetProjection(
                Projections.ProjectionList()
                .Add(Projections.GroupProperty("LotNo"))
                .Add(Projections.GroupProperty("od.OrderNo"))
                .Add(Projections.GroupProperty("ExternalReceiptNo"))
                .Add(Projections.GroupProperty("CreateDate"))
                .Add(Projections.GroupProperty("SettleTerm"))
                .Add(Projections.Sum("PlannedQty"))
                .Add(Projections.Sum("ActingQty"))
                );

            IList <int> idList = new List <int>();
            foreach (PlannedBill pb in plannedBillList)
            {
                idList.Add(pb.Id);
            }

            planBillDetailCriteria.Add(Expression.InG("Id", idList));

            this.GV_List.DataSource = ConvertPlanBill2CSInventoryDetail(this.TheCriteriaMgr.FindAll(planBillDetailCriteria));
            this.GV_List.DataBind();
        }
    }
Beispiel #15
0
        public async Task <Artiste> GetItemAsync(string id, string additionnalInfos = null)
        {
            Artiste tmpArtist = null;

            try
            {
                try
                {
                    if (lastArtist != null && lastArtist.ProviderId == id)
                    {
                        return(await Task.FromResult(lastArtist));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                if (id != null && id != "" && CrossConnectivity.Current.IsConnected)
                {
                    HttpClient client = new HttpClient();
                    //If mbid
                    if (id.Length == 36 && id.Contains("-"))
                    {
                        // Build an advanced query to search for the release.
                        //                            var query = new QueryParameters<Release>();
                        //                            query.Add("arid", id );
                        //                            query.Add("type", "album");
                        //                            query.Add("status", "official");
                        // Search for a release by title.

                        // Parallelise request to data providers
                        var artistRequest = Artist.GetAsync(id, "artist-rels", "url-rels", "event-rels",
                                                            "release-rels");
//                        var releasesRequest = Release.BrowseAsync("artist", id, 9);
                        var lastfmArtisTopAlbumsRequest = lastFm.Artist.GetTopAlbumsAsync(additionnalInfos);
                        var lastfmArtistRequest         = lastFm.Artist.GetInfoByMbidAsync(id, "fr");
                        var lastfmArtistSimilarsRequest = lastFm.Artist.GetSimilarByMbidAsync(id, false, 10);
                        var songKickUpEventRequest      = client.GetAsync("https://api.songkick.com/api/3.0/artists/mbid:"
                                                                          + id + "/calendar.json?apikey=" +
                                                                          App.SONGKICK_API_KEY);
                        //                        await Task.WhenAll(artistRequest, releasesRequest, lastfmArtistRequest);
                        await Task.WhenAll(artistRequest, lastfmArtisTopAlbumsRequest, lastfmArtistRequest,
                                           lastfmArtistSimilarsRequest, songKickUpEventRequest);

                        var artist = await artistRequest;
//                        var releases = await releasesRequest;
                        var lastfmArtisTopAlbums = await lastfmArtisTopAlbumsRequest;
                        var lastfmArtis          = await lastfmArtistRequest;
                        var lastfmArtistSimilars = await lastfmArtistSimilarsRequest;
                        var songKickUpEvent      = await songKickUpEventRequest;

                        // Use tmpArtist until full artist data are ok
                        tmpArtist = new Artiste(lastfmArtis.Content.Name, lastfmArtis.Content.Name, "",
                                                artist.LifeSpan.Begin,
                                                ConverterToViewObj.GetAge(artist.LifeSpan.Begin), artist.Country, artist.Type, "",
                                                ConverterToViewObj.ConvertRelToMap(artist.Relations, id), artist.Disambiguation,
                                                new List <Artiste>(), null,
                                                new List <Event>(), lastfmArtis.Content.Bio.Summary,
                                                lastfmArtis.Content.MainImage.Large.AbsoluteUri, id);

                        IListHelper.AddRange(tmpArtist.Projects,
                                             ConverterToViewObj.ConvertAlbums(lastfmArtisTopAlbums.Content));
                        IListHelper.AddRange(tmpArtist.Similars,
                                             ConverterToViewObj.ConvertArtistes(lastfmArtistSimilars.Content));

                        var songKickUpEvt = await songKickUpEvent.Content.ReadAsStringAsync();

                        IListHelper.AddRange(tmpArtist.UpEvents, ConverterToViewObj.ConvertSkEvents(songKickUpEvt));

                        // If no album loaded with last.fm, try with Musicbrainz
                        if (tmpArtist.Projects?.Count == 0)
                        {
//                             Load releases and releases img from MB parallele
                            var releases = await Release.BrowseAsync("artist", id, 9);

                            List <Task <Release> >             requestRelease  = new List <Task <Release> >();
                            List <Task <HttpResponseMessage> > releaseImageUrl = new List <Task <HttpResponseMessage> >();
                            foreach (var release in releases.Items)
                            {
                                requestRelease.Add(Release.GetAsync(release.Id, "recordings", "artist-credits",
                                                                    "url-rels"));
                                var image_uri = new Uri("http://coverartarchive.org/release/" + release.Id);
                                releaseImageUrl.Add(client.GetAsync(image_uri));
                            }

                            var loadedReleases = await Task.WhenAll(requestRelease);

                            var releaseImages = await Task.WhenAll(releaseImageUrl);

                            List <Task <string> > imgContents = new List <Task <string> >();
                            foreach (var relImg in releaseImages)
                            {
                                var content = relImg.Content.ReadAsStringAsync();
                                imgContents.Add(content);
                            }

                            var imgs = await Task.WhenAll(imgContents);

                            // Try to parse json img response
                            List <string> urlList = new List <string>();
                            foreach (var img in imgs)
                            {
                                string url = null;
                                try
                                {
                                    dynamic json = JsonConvert.DeserializeObject(img);
                                    url = json.images[0].image;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }

                                urlList.Add(url);
                            }

                            IListHelper.AddRange(tmpArtist.Projects,
                                                 ConverterToViewObj.ConvertMbAlbums(loadedReleases, urlList));
                        }

                        lastArtist = tmpArtist;

                        return(await Task.FromResult(tmpArtist));
                    }
                    else
                    {
                        //TODO: test paralelle async call
                        var syncArtist   = lastFm.Artist.GetInfoAsync(id, "fr");
                        var syncAlbums   = lastFm.Artist.GetTopAlbumsAsync(id);
                        var syncSimilars = lastFm.Artist.GetTopAlbumsAsync(id, false, 1, 10);
                        await Task.WhenAll(syncArtist, syncAlbums, syncSimilars);

                        var lastfmArtis          = await syncArtist;
                        var lastfmArtisTopAlbums = await syncAlbums;
                        var lastfmArtisSimilars  = await syncSimilars;

                        tmpArtist = new Artiste(lastfmArtis.Content.Name, lastfmArtis.Content.Name, "", "",
                                                0, "", "", "", new List <MyKeyValuePair>(), "",
                                                new List <Artiste>(),
                                                ConverterToViewObj.ConvertAlbums(lastfmArtisTopAlbums.Content),
                                                new List <Event>(), lastfmArtis.Content.Bio.Summary,
                                                lastfmArtis.Content.MainImage.Large.AbsoluteUri, id);
                        lastArtist = tmpArtist;

                        return(await Task.FromResult(tmpArtist));
                    }
                }

                return(await Task.FromResult(lastArtist));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(await Task.FromResult(tmpArtist));
            }
        }
Beispiel #16
0
        public IList <CustomerScheduleDetail> GetEffectiveCustomerScheduleDetail(IList <CustomerScheduleDetail> customerScheduleDetailList, DateTime effectiveDate)
        {
            IList <CustomerScheduleDetail> effectiveCustomerScheduleDetailList = new List <CustomerScheduleDetail>();

            if (customerScheduleDetailList != null && customerScheduleDetailList.Count > 0)
            {
                #region 根据Flow分组
                var groupedCustomerScheduleDetailList = from det in customerScheduleDetailList
                                                        where det.DateFrom >= effectiveDate
                                                        group det by det.CustomerSchedule.Flow into result
                                                        select new
                {
                    Flow = result.Key,
                    List = result.ToList()
                };
                #endregion

                if (groupedCustomerScheduleDetailList != null && groupedCustomerScheduleDetailList.Count() > 0)
                {
                    foreach (var groupedCustomerScheduleDetail in groupedCustomerScheduleDetailList)
                    {
                        IList <CustomerScheduleDetail> detList = groupedCustomerScheduleDetail.List;

                        #region 根据Id分组(按客户日程分组)
                        var groupedDetailList = from det in detList
                                                group det by det.CustomerSchedule.Id into result
                                                select new
                        {
                            Id   = result.Key,
                            List = result.ToList()
                        };
                        #endregion

                        #region 再根据Id排序
                        var orderedAndGroupedDetailList = from det in groupedDetailList
                                                          orderby det.Id descending
                                                          select det;
                        #endregion

                        #region 循环获取有效日程
                        DateTime?minDateFrom = null;   //最新日程的最小开始日期,旧的日程取比开始日期小的列
                        foreach (var orderedAndGroupedDetail in orderedAndGroupedDetailList)
                        {
                            if (!minDateFrom.HasValue)
                            {
                                //最新日程,全部是有效的
                                IListHelper.AddRange <CustomerScheduleDetail>(effectiveCustomerScheduleDetailList, orderedAndGroupedDetail.List.OrderBy(o => o.DateFrom).ToList());
                            }
                            else
                            {
                                #region 旧日程,只有小于最小开始日期是有效的
                                var effDetail = (from det in orderedAndGroupedDetail.List
                                                 where det.DateFrom < minDateFrom
                                                 select det).OrderBy(o => o.DateFrom);

                                if (effDetail != null && effDetail.Count() > 0)
                                {
                                    IListHelper.AddRange <CustomerScheduleDetail>(effectiveCustomerScheduleDetailList, effDetail.ToList());
                                }
                                else
                                {
                                    continue;
                                }
                                #endregion
                            }

                            //最小开始日期赋值
                            minDateFrom = (from det in orderedAndGroupedDetail.List
                                           orderby det.DateFrom ascending
                                           select det.DateFrom).FirstOrDefault();
                        }
                        #endregion
                    }
                }
            }

            return(effectiveCustomerScheduleDetailList);
        }
Beispiel #17
0
        public void CreateReceipt(Receipt receipt, User user, bool isOddCreateHu)
        {
            log.Debug("Start create receipt");
            #region 查找所有的发货项,收货单打印模板,收货差异处理选项
            string      orderType       = null;
            Party       partyFrom       = null;
            Party       partyTo         = null;
            ShipAddress shipFrom        = null;
            ShipAddress shipTo          = null;
            string      dockDescription = null;
            string      receiptTemplate = null;
            string      huTemplate      = null;
            string      grGapTo         = null;
            IList <InProcessLocationDetail> inProcessLocationDetailList = new List <InProcessLocationDetail>();
            if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in receipt.InProcessLocations)
                {
                    InProcessLocation currentIp = inProcessLocationMgr.LoadInProcessLocation(inProcessLocation.IpNo);
                    if (currentIp.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE)
                    {
                        throw new BusinessErrorException("InProcessLocation.Error.StatusErrorWhenReceive", currentIp.Status, currentIp.IpNo);
                    }

                    if (orderType == null)
                    {
                        orderType = inProcessLocation.OrderType;
                    }

                    //判断OrderHead的PartyFrom是否一致
                    if (partyFrom == null)
                    {
                        partyFrom = inProcessLocation.PartyFrom;
                    }
                    else if (inProcessLocation.PartyFrom.Code != partyFrom.Code)
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.PartyFromNotEqual");
                    }

                    //判断OrderHead的PartyFrom是否一致
                    if (partyTo == null)
                    {
                        partyTo = inProcessLocation.PartyTo;
                    }
                    else if (inProcessLocation.PartyTo.Code != partyTo.Code)
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.PartyToNotEqual");
                    }

                    //判断OrderHead的ShipFrom是否一致
                    if (shipFrom == null)
                    {
                        shipFrom = inProcessLocation.ShipFrom;
                    }
                    else if (!AddressHelper.IsAddressEqual(inProcessLocation.ShipFrom, shipFrom))
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.ShipFromNotEqual");
                    }

                    //判断OrderHead的ShipTo是否一致
                    if (shipTo == null)
                    {
                        shipTo = inProcessLocation.ShipTo;
                    }
                    else if (!AddressHelper.IsAddressEqual(inProcessLocation.ShipTo, shipTo))
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.ShipToNotEqual");
                    }

                    if (dockDescription == null)
                    {
                        dockDescription = inProcessLocation.DockDescription;
                    }
                    else if (inProcessLocation.DockDescription != dockDescription)
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.DockDescriptionNotEqual");
                    }

                    //判断收货单打印模板是否一致
                    if (receiptTemplate == null)
                    {
                        receiptTemplate = inProcessLocation.ReceiptTemplate;
                    }
                    else
                    {
                        if (inProcessLocation.ReceiptTemplate != null && inProcessLocation.ReceiptTemplate != receiptTemplate)
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveOrder.ReceiptTemplateNotEqual");
                        }
                    }

                    //判断条码打印模板是否一致
                    if (huTemplate == null)
                    {
                        huTemplate = inProcessLocation.HuTemplate;
                    }
                    else
                    {
                        if (inProcessLocation.HuTemplate != null && inProcessLocation.HuTemplate != huTemplate)
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveOrder.HuTemplateNotEqual");
                        }
                    }

                    #region 查找收货差异处理选项
                    if (grGapTo == null)
                    {
                        grGapTo = inProcessLocation.GoodsReceiptGapTo;
                    }
                    else
                    {
                        if (inProcessLocation.GoodsReceiptGapTo != null && inProcessLocation.GoodsReceiptGapTo != grGapTo)
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveOrder.GoodsReceiptGapToNotEqual");
                        }
                    }
                    #endregion

                    IListHelper.AddRange <InProcessLocationDetail>(
                        inProcessLocationDetailList, this.inProcessLocationDetailMgr.GetInProcessLocationDetail(inProcessLocation));
                }
            }
            #endregion

            IList <ReceiptDetail> targetReceiptDetailList = receipt.ReceiptDetails;
            receipt.ReceiptDetails = null;   //清空Asn明细,稍后填充

            #region 创建收货单Head
            receipt.ReceiptNo       = numberControlMgr.GenerateNumber(BusinessConstants.CODE_PREFIX_RECEIPT);
            receipt.OrderType       = orderType;
            receipt.CreateDate      = DateTime.Now;
            receipt.CreateUser      = user;
            receipt.PartyFrom       = partyFrom;
            receipt.PartyTo         = partyTo;
            receipt.ShipFrom        = shipFrom;
            receipt.ShipTo          = shipTo;
            receipt.DockDescription = dockDescription;
            receipt.ReceiptTemplate = receiptTemplate;
            receipt.IsPrinted       = false;
            receipt.NeedPrint       = false;
            if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in receipt.InProcessLocations)
                {
                    if (inProcessLocation.NeedPrintReceipt)
                    {
                        receipt.NeedPrint = true;
                        break;
                    }
                }
            }

            this.CreateReceipt(receipt);
            log.Debug("Create receipt " + receipt.ReceiptNo + " head successful");
            #endregion

            #region HU处理/入库操作/创建收货明细
            log.Debug("Start create receipt detail");
            IList <LocationLotDetail> inspectLocationLotDetailList = new List <LocationLotDetail>();
            foreach (ReceiptDetail receiptDetail in targetReceiptDetailList)
            {
                OrderLocationTransaction orderLocationTransaction = receiptDetail.OrderLocationTransaction;
                OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                OrderHead   orderHead   = orderDetail.OrderHead;

                if (orderHead.CreateHuOption == BusinessConstants.CODE_MASTER_CREATE_HU_OPTION_VALUE_GR &&
                    receiptDetail.HuId == null)         //如果订单设置为收货时创建Hu,但是收货时已经扫描过Hu了,按已扫描处理
                {
                    #region 收货时创建Hu
                    log.Debug("Create receipt detail with generate barcode.");
                    #region 生产本次收货+剩余零头生成Hu
                    decimal oddQty = 0;

                    if (!isOddCreateHu && orderDetail.HuLotSize.HasValue &&
                        orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)    //只有生产支持零头
                    {
                        #region 查找剩余零头 + 本次收货数是否能够生成Hu
                        Hu oddHu = this.CreateHuFromOdd(receiptDetail, user);
                        if (oddHu != null)
                        {
                            log.Debug("Generate barcode using odd qty.");
                            //如果零头生成了Hu,本次收货数会扣减
                            #region 创建Hu
                            IList <Hu> oddHuList = new List <Hu>();
                            oddHuList.Add(oddHu);
                            IList <ReceiptDetail> oddReceiptDetailList = this.receiptDetailMgr.CreateReceiptDetail(receipt, orderLocationTransaction, oddHuList);
                            log.Debug("Generate odd barcode successful.");
                            #endregion

                            #region 入库
                            IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(oddReceiptDetailList[0], user, receiptDetail.PutAwayBinCode);
                            log.Debug("odd Inventory in successful.");
                            #endregion

                            #region 是否检验
                            if (orderDetail.NeedInspection && orderHead.NeedInspection && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML)
                            {
                                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                                {
                                    LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                                    locationLotDetail.CurrentInspectQty = locationLotDetail.Qty;
                                    inspectLocationLotDetailList.Add(locationLotDetail);
                                }
                            }
                            #endregion
                        }
                        #endregion

                        oddQty = receiptDetail.ReceivedQty.HasValue && orderDetail.HuLotSize.HasValue ?
                                 receiptDetail.ReceivedQty.Value % orderDetail.HuLotSize.Value : 0; //收货零头数
                        log.Debug("Receive odd qty is " + oddQty);

                        receiptDetail.ReceivedQty = receiptDetail.ReceivedQty.Value - oddQty; //收货数量凑整
                    }
                    #endregion

                    #region 满包装/零头创建Hu处理
                    if (receiptDetail.ReceivedQty.HasValue ||
                        receiptDetail.RejectedQty.HasValue ||
                        receiptDetail.ScrapQty.HasValue)
                    {
                        //创建Hu
                        IList <Hu> huList = this.huMgr.CreateHu(receiptDetail, user);
                        log.Debug("Create barcode successful.");

                        //创建收货项
                        IList <ReceiptDetail> receiptDetailList = this.receiptDetailMgr.CreateReceiptDetail(receipt, orderLocationTransaction, huList);
                        log.Debug("Create receipt detail successful.");

                        #region 如果还有次品或者废品收货,添加到收货列表
                        if ((receiptDetail.RejectedQty.HasValue && receiptDetail.RejectedQty > 0) ||
                            (receiptDetail.ScrapQty.HasValue && receiptDetail.ScrapQty > 0))
                        {
                            ReceiptDetail rejAndScrapReceiptDetail = new ReceiptDetail();
                            CloneHelper.CopyProperty(receiptDetail, rejAndScrapReceiptDetail);
                            rejAndScrapReceiptDetail.ReceivedQty    = null;
                            rejAndScrapReceiptDetail.PutAwayBinCode = null;
                            rejAndScrapReceiptDetail.Receipt        = receipt;

                            this.receiptDetailMgr.CreateReceiptDetail(rejAndScrapReceiptDetail);

                            receiptDetailList.Add(rejAndScrapReceiptDetail);
                            receipt.AddReceiptDetail(rejAndScrapReceiptDetail);
                        }
                        #endregion

                        foreach (ReceiptDetail huReceiptDetail in receiptDetailList)
                        {
                            #region 匹配ReceiptDetail和InProcessLocationDetail,Copy相关信息
                            if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                            {
                                IList <InProcessLocationDetail> matchInProcessLocationDetailList = OrderHelper.FindMatchInProcessLocationDetail(receiptDetail, inProcessLocationDetailList);
                                if (matchInProcessLocationDetailList != null && matchInProcessLocationDetailList.Count > 0)
                                {
                                    if (matchInProcessLocationDetailList.Count > 1)
                                    {
                                        //只有当ASN中包含条码,按数量收货,并收货后创建条码才有可能发生这种情况。
                                        //变态才这么干。
                                        log.Error("只有当ASN中包含条码,按数量收货,并收货后创建条码才有可能发生这种情况。");
                                        throw new BusinessErrorException("你是变态才这么设置。");
                                    }

                                    //如果找到匹配项,只可能有一个
                                    huReceiptDetail.PlannedBill   = matchInProcessLocationDetailList[0].PlannedBill;
                                    huReceiptDetail.IsConsignment = matchInProcessLocationDetailList[0].IsConsignment;
                                    huReceiptDetail.ShippedQty    = matchInProcessLocationDetailList[0].Qty;

                                    this.receiptDetailMgr.UpdateReceiptDetail(huReceiptDetail);
                                }

                                //收货创建HU,分配PlannedAmount,todo:考虑余数
                                huReceiptDetail.PlannedAmount = receiptDetail.PlannedAmount / receiptDetail.ReceivedQty.Value * huReceiptDetail.ReceivedQty.Value;
                            }
                            #endregion

                            #region 入库
                            IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(huReceiptDetail, user, receiptDetail.PutAwayBinCode);
                            log.Debug("Inventory in successful.");
                            #endregion

                            #region 是否检验
                            if (orderDetail.NeedInspection &&
                                orderHead.NeedInspection &&
                                orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML &&
                                huReceiptDetail.ReceivedQty.HasValue &&
                                huReceiptDetail.ReceivedQty > 0)
                            {
                                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                                {
                                    if (inventoryTransaction.Location.Code != BusinessConstants.SYSTEM_LOCATION_REJECT)
                                    {
                                        LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                                        locationLotDetail.CurrentInspectQty = inventoryTransaction.Qty;
                                        inspectLocationLotDetailList.Add(locationLotDetail);
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region 生产剩余零头处理
                    if (oddQty > 0)
                    {
                        log.Debug("Start handle odd qty.");
                        ReceiptDetail oddReceiptDetail = new ReceiptDetail();
                        CloneHelper.CopyProperty(receiptDetail, oddReceiptDetail);

                        oddReceiptDetail.ReceivedQty = oddQty;
                        oddReceiptDetail.RejectedQty = 0;
                        oddReceiptDetail.ScrapQty    = 0;

                        #region 零头入库
                        oddReceiptDetail.Receipt = receipt;
                        IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(oddReceiptDetail, user, receiptDetail.PutAwayBinCode);
                        #endregion

                        #region 零头创建收货明细
                        this.receiptDetailMgr.CreateReceiptDetail(oddReceiptDetail);
                        receipt.AddReceiptDetail(oddReceiptDetail);
                        #endregion

                        #region 创建HuOdd
                        LocationLotDetail locationLotDetail = locationLotDetailMgr.LoadLocationLotDetail(inventoryTransactionList[0].LocationLotDetailId);
                        this.huOddMgr.CreateHuOdd(oddReceiptDetail, locationLotDetail, user);
                        #endregion
                        log.Debug("End handle odd qty.");
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    #region 收货时不创建Hu
                    log.Debug("Create receipt detail with no generate barcode.");

                    #region 更新Hu上的OrderNo、ReceiptNo和AntiResloveHu
                    if (receiptDetail.HuId != null && receiptDetail.HuId.Trim() != string.Empty)
                    {
                        Hu   hu        = this.huMgr.LoadHu(receiptDetail.HuId);
                        bool isUpdated = false;

                        if (hu.OrderNo == null || hu.ReceiptNo == null)
                        {
                            if (hu.OrderNo == null)
                            {
                                log.Debug("Update hu OrderNo " + orderHead.OrderNo + ".");
                                hu.OrderNo = orderHead.OrderNo;
                            }

                            if (hu.ReceiptNo == null)
                            {
                                log.Debug("Update hu ReceiptNo " + receipt.ReceiptNo + ".");
                                hu.ReceiptNo = receipt.ReceiptNo;
                            }

                            isUpdated = true;
                        }

                        if (hu.AntiResolveHu == null &&
                            orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
                        {
                            hu.AntiResolveHu = orderHead.AntiResolveHu;
                            isUpdated        = true;
                        }

                        if (isUpdated)
                        {
                            this.huMgr.UpdateHu(hu);
                        }
                    }
                    #endregion

                    IList <ReceiptDetail> noCreateHuReceiptDetailList = new List <ReceiptDetail>();

                    #region 匹配ReceiptDetail和InProcessLocationDetail,Copy相关信息
                    log.Debug("Start match ReceiptDetail and InProcessLocationDetail.");
                    if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION &&
                        orderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ)     //收货调整已经匹配过InProcessLocationDetail,不需要在匹配
                    {
                        IList <InProcessLocationDetail> matchInProcessLocationDetailList = OrderHelper.FindMatchInProcessLocationDetail(receiptDetail, inProcessLocationDetailList);
                        log.Debug("Find matched InProcessLocationDetailList, count = " + matchInProcessLocationDetailList != null ? matchInProcessLocationDetailList.Count : 0);

                        if (matchInProcessLocationDetailList != null && matchInProcessLocationDetailList.Count == 1)
                        {
                            //一次收货对应一次发货。
                            log.Debug("one ipdet vs one receiptdet.");
                            receiptDetail.PlannedBill   = matchInProcessLocationDetailList[0].PlannedBill;
                            receiptDetail.IsConsignment = matchInProcessLocationDetailList[0].IsConsignment;
                            if (matchInProcessLocationDetailList[0].InProcessLocation.Type == BusinessConstants.CODE_MASTER_INPROCESS_LOCATION_TYPE_VALUE_GAP)
                            {
                                receiptDetail.ShippedQty = 0 - matchInProcessLocationDetailList[0].Qty;
                            }
                            else
                            {
                                receiptDetail.ShippedQty = matchInProcessLocationDetailList[0].Qty;
                            }
                            receiptDetail.ReceivedInProcessLocationDetail = matchInProcessLocationDetailList[0];
                            noCreateHuReceiptDetailList.Add(receiptDetail);
                        }
                        else if (matchInProcessLocationDetailList != null && matchInProcessLocationDetailList.Count > 1)
                        {
                            //一次收货对应多次发货。
                            //如:发货按条码,收货按数量。
                            log.Debug("multi ipdet vs one receiptdet.");
                            decimal totalRecQty = receiptDetail.ReceivedQty.Value;
                            InProcessLocationDetail lastInProcessLocationDetail = null;
                            log.Debug("Start Fetch matched InProcessLocationDetailList.");
                            foreach (InProcessLocationDetail inProcessLocationDetail in matchInProcessLocationDetailList)
                            {
                                lastInProcessLocationDetail = inProcessLocationDetail; //记录最后一次发货项,供没有对应发货的收货项使用

                                if (inProcessLocationDetail.ReceivedQty.HasValue && Math.Abs(inProcessLocationDetail.ReceivedQty.Value) >= Math.Abs(inProcessLocationDetail.Qty))
                                {
                                    continue;
                                }

                                if (Math.Abs(totalRecQty) > 0)
                                {
                                    log.Debug("Start cloned ReceiptDetail.");
                                    ReceiptDetail clonedReceiptDetail = new ReceiptDetail();
                                    CloneHelper.CopyProperty(receiptDetail, clonedReceiptDetail);
                                    log.Debug("End cloned ReceiptDetail.");

                                    clonedReceiptDetail.PlannedBill   = inProcessLocationDetail.PlannedBill;
                                    clonedReceiptDetail.IsConsignment = inProcessLocationDetail.IsConsignment;

                                    #region
                                    if (matchInProcessLocationDetailList[0].InProcessLocation.Type == BusinessConstants.CODE_MASTER_INPROCESS_LOCATION_TYPE_VALUE_GAP)
                                    {
                                        inProcessLocationDetail.Qty = 0 - inProcessLocationDetail.Qty;
                                    }
                                    #endregion

                                    if (Math.Abs(totalRecQty) > Math.Abs(inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero)))
                                    {
                                        clonedReceiptDetail.ReceivedQty = inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero);
                                        clonedReceiptDetail.ShippedQty  = inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero);
                                        totalRecQty -= inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero);
                                    }
                                    else
                                    {
                                        clonedReceiptDetail.ReceivedQty = totalRecQty;
                                        clonedReceiptDetail.ShippedQty  = totalRecQty;
                                        totalRecQty = 0;
                                    }

                                    //因为去掉了数量,记录已经匹配的发货项,避免差异处理的时候匹配多条而产生差异。
                                    clonedReceiptDetail.ReceivedInProcessLocationDetail = inProcessLocationDetail;

                                    noCreateHuReceiptDetailList.Add(clonedReceiptDetail);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            log.Debug("End Fetch matched InProcessLocationDetailList.");

                            //超收,没有找到对应的发货项,只记录收货数,发货数记0
                            if (Math.Abs(totalRecQty) > 0)
                            {
                                ReceiptDetail clonedReceiptDetail = new ReceiptDetail();
                                CloneHelper.CopyProperty(receiptDetail, clonedReceiptDetail);

                                clonedReceiptDetail.ShippedQty  = 0;
                                clonedReceiptDetail.ReceivedQty = totalRecQty;
                                clonedReceiptDetail.ReceivedInProcessLocationDetail = lastInProcessLocationDetail;

                                noCreateHuReceiptDetailList.Add(clonedReceiptDetail);
                            }
                        }
                        else
                        {
                            noCreateHuReceiptDetailList.Add(receiptDetail);
                        }
                    }
                    else
                    {
                        noCreateHuReceiptDetailList.Add(receiptDetail);
                    }
                    log.Debug("End match ReceiptDetail and InProcessLocationDetail.");
                    #endregion

                    foreach (ReceiptDetail noCreateHuReceiptDetail in noCreateHuReceiptDetailList)
                    {
                        noCreateHuReceiptDetail.Receipt = receipt;

                        if (noCreateHuReceiptDetail.ReceivedQty != 0)
                        {
                            #region 入库
                            log.Debug("Start Inventory In.");
                            IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(noCreateHuReceiptDetail, user, noCreateHuReceiptDetail.PutAwayBinCode);
                            log.Debug("End Inventory In.");
                            #endregion

                            #region 是否检验
                            if (orderDetail.NeedInspection && orderHead.NeedInspection && inventoryTransactionList != null && inventoryTransactionList.Count > 0 &&
                                orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML)
                            {
                                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                                {
                                    if (inventoryTransaction.Location.Code != BusinessConstants.SYSTEM_LOCATION_REJECT)
                                    {
                                        LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                                        locationLotDetail.CurrentInspectQty = inventoryTransaction.Qty;
                                        inspectLocationLotDetailList.Add(locationLotDetail);
                                    }
                                }
                            }
                            #endregion
                        }

                        #region 创建收货明细
                        log.Debug("Start Create Receipt Detail.");
                        this.receiptDetailMgr.CreateReceiptDetail(noCreateHuReceiptDetail);
                        receipt.AddReceiptDetail(noCreateHuReceiptDetail);
                        log.Debug("End Create Receipt Detail.");
                        #endregion
                    }

                    #endregion
                }
            }
            #endregion

            #region 检验
            if (inspectLocationLotDetailList.Count > 0)
            {
                //对于没有Hu的,如果收货时已经回冲了负数库存,也就是库存数量和待检验数量不一致可能会有问题
                //增加ipno,receiptno,isseperated字段
                this.inspectOrderMgr.CreateInspectOrder(inspectLocationLotDetailList, user, receipt.InProcessLocations[0].IpNo, receipt.ReceiptNo, false);
            }
            #endregion

            //#region 匹配收货发货项,查找差异
            //IList<InProcessLocationDetail> gapInProcessLocationDetailList = new List<InProcessLocationDetail>();

            //#region 发货项不匹配
            //foreach (InProcessLocationDetail inProcessLocationDetail in inProcessLocationDetailList)
            //{
            //    if (inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.Type
            //        != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)   //生产暂时不支持差异
            //    {
            //        decimal receivedQty = 0;  //发货项的累计收货数

            //        //一条发货项可能对应多条收货项
            //        foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
            //        {
            //            //匹配收货项和发货项
            //            if (receiptDetail.ReceivedInProcessLocationDetail != null)
            //            {
            //                //对于已经匹配的,直接按发货项匹配
            //                if (receiptDetail.ReceivedInProcessLocationDetail.Id == inProcessLocationDetail.Id)
            //                {
            //                    if (receiptDetail.ReceivedQty.HasValue)
            //                    {
            //                        receivedQty += receiptDetail.ReceivedQty.Value;
            //                    }
            //                }
            //            }
            //            else if (OrderHelper.IsInProcessLocationDetailMatchReceiptDetail(
            //                inProcessLocationDetail, receiptDetail))
            //            {
            //                if (receiptDetail.ReceivedQty.HasValue)
            //                {
            //                    receivedQty += receiptDetail.ReceivedQty.Value;
            //                }
            //            }
            //        }

            //        if (receivedQty != inProcessLocationDetail.Qty)
            //        {
            //            #region 收货数量和发货数量不匹配,记录差异
            //            InProcessLocationDetail gapInProcessLocationDetail = new InProcessLocationDetail();
            //            gapInProcessLocationDetail.Qty = receivedQty - inProcessLocationDetail.Qty;
            //            gapInProcessLocationDetail.OrderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
            //            //gapInProcessLocationDetail.HuId = inProcessLocationDetail.HuId;
            //            gapInProcessLocationDetail.LotNo = inProcessLocationDetail.LotNo;
            //            gapInProcessLocationDetail.IsConsignment = inProcessLocationDetail.IsConsignment;
            //            gapInProcessLocationDetail.PlannedBill = inProcessLocationDetail.PlannedBill;

            //            gapInProcessLocationDetailList.Add(gapInProcessLocationDetail);
            //            #endregion
            //        }
            //    }
            //}
            //#endregion

            //#region 收货项不匹配
            //foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
            //{
            //    if (receiptDetail.OrderLocationTransaction.OrderDetail.OrderHead.Type
            //        != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)   //生产暂时不支持差异
            //    {
            //        IList<InProcessLocationDetail> matchInProcessLocationDetailList = OrderHelper.FindMatchInProcessLocationDetail(receiptDetail, inProcessLocationDetailList);

            //        if (matchInProcessLocationDetailList == null || matchInProcessLocationDetailList.Count == 0)
            //        {
            //            OrderLocationTransaction outOrderLocationTransaction =
            //                this.orderLocationTransactionMgr.GetOrderLocationTransaction(receiptDetail.OrderLocationTransaction.OrderDetail, BusinessConstants.IO_TYPE_OUT)[0];
            //            #region 没有找到和收货项对应的发货项
            //            InProcessLocationDetail gapInProcessLocationDetail = new InProcessLocationDetail();
            //            gapInProcessLocationDetail.Qty = receiptDetail.ReceivedQty.Value;
            //            gapInProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
            //            //gapInProcessLocationDetail.HuId = receiptDetail.HuId;
            //            gapInProcessLocationDetail.LotNo = receiptDetail.LotNo;
            //            gapInProcessLocationDetail.IsConsignment = receiptDetail.IsConsignment;
            //            gapInProcessLocationDetail.PlannedBill = receiptDetail.PlannedBill;

            //            gapInProcessLocationDetailList.Add(gapInProcessLocationDetail);
            //            #endregion
            //        }
            //    }
            //}
            //#endregion
            //#endregion

            #region 关闭InProcessLocation
            if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in receipt.InProcessLocations)
                {
                    if (inProcessLocation.IsAsnUniqueReceipt)
                    {
                        //不支持多次收货直接关闭
                        this.inProcessLocationMgr.CloseInProcessLocation(inProcessLocation, user);
                    }
                    else
                    {
                        this.inProcessLocationMgr.TryCloseInProcessLocation(inProcessLocation, user);
                    }

                    //transportationOrderMgr.TryCompleteTransportationOrder(inProcessLocation, user);
                }
            }
            #endregion
        }
Beispiel #18
0
        public PickList CreatePickList(IList <OrderLocationTransaction> orderLocationTransactionList, User user)
        {
            List <OrderLocationTransaction>  targetOrderLocationTransactionList = new List <OrderLocationTransaction>();
            OrderLocationTransactionComparer orderLocationTransactionComparer   = new OrderLocationTransactionComparer();

            if (orderLocationTransactionList != null && orderLocationTransactionList.Count > 0)
            {
                foreach (OrderLocationTransaction orderLocationTransaction in orderLocationTransactionList)
                {
                    if (orderLocationTransaction.CurrentShipQty > 0)
                    {
                        targetOrderLocationTransactionList.Add(orderLocationTransaction);
                    }
                }
            }

            if (targetOrderLocationTransactionList.Count == 0)
            {
                throw new BusinessErrorException("Order.Error.PickUp.DetailEmpty");
            }
            else
            {
                //按FromLocation、零件号、单位、单包装排序
                targetOrderLocationTransactionList.Sort(orderLocationTransactionComparer);
            }

            string      orderType          = null;
            Party       partyFrom          = null;
            Party       partyTo            = null;
            ShipAddress shipFrom           = null;
            ShipAddress shipTo             = null;
            string      dockDescription    = null;
            bool?       isShipScanHu       = null;
            bool?       isReceiptScanHu    = null;
            bool?       isAutoReceive      = null;
            decimal?    completeLatency    = null;
            string      grGapTo            = null;
            string      asnTemplate        = null;
            string      receiptTemplate    = null;
            string      flow               = null;
            DateTime?   windowTime         = null;
            bool?       isAsnUniqueReceipt = null;

            #region 判断OrderHead的PartyFrom, PartyTo, ShipFrom, ShipTo, DockDescription是否一致
            foreach (OrderLocationTransaction orderLocationTransaction in targetOrderLocationTransactionList)
            {
                OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                OrderHead   orderHead   = orderDetail.OrderHead;

                //判断OrderHead的Type是否一致
                if (orderType == null)
                {
                    orderType = orderHead.Type;
                }
                else if (orderHead.Type != orderType)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.OrderTypeNotEqual");
                }

                //判断OrderHead的PartyFrom是否一致
                if (partyFrom == null)
                {
                    partyFrom = orderHead.PartyFrom;
                }
                else if (orderHead.PartyFrom.Code != partyFrom.Code)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.PartyFromNotEqual");
                }

                //判断OrderHead的PartyFrom是否一致
                if (partyTo == null)
                {
                    partyTo = orderHead.PartyTo;
                }
                else if (orderHead.PartyTo.Code != partyTo.Code)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.PartyToNotEqual");
                }

                //判断OrderHead的ShipFrom是否一致
                if (shipFrom == null)
                {
                    shipFrom = orderHead.ShipFrom;
                }
                else if (!AddressHelper.IsAddressEqual(orderHead.ShipFrom, shipFrom))
                {
                    throw new BusinessErrorException("Order.Error.PickUp.ShipFromNotEqual");
                }

                //判断OrderHead的ShipTo是否一致
                if (shipTo == null)
                {
                    shipTo = orderHead.ShipTo;
                }
                else if (!AddressHelper.IsAddressEqual(orderHead.ShipTo, shipTo))
                {
                    throw new BusinessErrorException("Order.Error.PickUp.ShipToNotEqual");
                }

                //判断OrderHead的DockDescription是否一致
                if (dockDescription == null)
                {
                    dockDescription = orderHead.DockDescription;
                }
                else if (orderHead.DockDescription != dockDescription)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.DockDescriptionNotEqual");
                }

                //判断OrderHead的IsShipScanHu是否一致
                if (isShipScanHu == null)
                {
                    isShipScanHu = orderHead.IsShipScanHu;
                }
                else if (orderHead.IsShipScanHu != isShipScanHu)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.IsShipScanHuNotEqual");
                }

                //判断OrderHead的IsReceiptScanHu是否一致
                if (isReceiptScanHu == null)
                {
                    isReceiptScanHu = orderHead.IsReceiptScanHu;
                }
                else if (orderHead.IsReceiptScanHu != isReceiptScanHu)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.IsReceiptScanHuNotEqual");
                }

                //判断OrderHead的IsAutoReceipt是否一致
                if (isAutoReceive == null)
                {
                    isAutoReceive = orderHead.IsAutoReceive;
                }
                else if (orderHead.IsAutoReceive != isAutoReceive)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.IsAutoReceiveNotEqual");
                }

                //判断OrderHead的CompleteLatency是否一致
                if (completeLatency == null)
                {
                    completeLatency = orderHead.CompleteLatency;
                }
                else
                {
                    if (orderHead.CompleteLatency.HasValue && orderHead.CompleteLatency != completeLatency)
                    {
                        throw new BusinessErrorException("Order.Error.PickUp.CompleteLatencyNotEqual");
                    }
                }

                //判断OrderHead的GoodsReceiptGapTo是否一致
                if (grGapTo == null)
                {
                    grGapTo = orderHead.GoodsReceiptGapTo;
                }
                else
                {
                    if (orderHead.GoodsReceiptGapTo != null && orderHead.GoodsReceiptGapTo != grGapTo)
                    {
                        throw new BusinessErrorException("Order.Error.PickUp.GoodsReceiptGapToNotEqual");
                    }
                }

                //判断OrderHead的AsnTemplate是否一致
                if (asnTemplate == null)
                {
                    asnTemplate = orderHead.AsnTemplate;
                }
                else
                {
                    if (orderHead.AsnTemplate != null && orderHead.AsnTemplate != asnTemplate)
                    {
                        throw new BusinessErrorException("Order.Error.PickUp.AsnTemplateNotEqual");
                    }
                }

                //判断OrderHead的ReceiptTemplate是否一致
                if (receiptTemplate == null)
                {
                    receiptTemplate = orderHead.ReceiptTemplate;
                }
                else
                {
                    if (orderHead.ReceiptTemplate != null && orderHead.ReceiptTemplate != receiptTemplate)
                    {
                        throw new BusinessErrorException("Order.Error.PickUp.ReceiptTemplateNotEqual");
                    }
                }

                //判断OrderHead的Flow是否一致
                if (flow == null)
                {
                    flow = orderHead.Flow;
                }
                else if (orderHead.Flow != flow)
                {
                    //throw new BusinessErrorException("Order.Error.PickUp.FlowNotEqual");
                }

                //寻找最小的WindowTime
                if (!windowTime.HasValue)
                {
                    windowTime = orderHead.WindowTime;
                }
                else if (windowTime.Value > orderHead.WindowTime)
                {
                    windowTime = orderHead.WindowTime;
                }

                //判断OrderHead的IsAsnUniqueReceipt是否一致
                if (isAsnUniqueReceipt == null)
                {
                    isAsnUniqueReceipt = orderHead.IsAsnUniqueReceipt;
                }
                else if (orderHead.IsAsnUniqueReceipt != isAsnUniqueReceipt)
                {
                    throw new BusinessErrorException("Order.Error.PickUp.IsAsnUniqueReceiptNotEqual");
                }
            }
            #endregion

            #region 创建捡货单头
            DateTime dateTimeNow = DateTime.Now;

            PickList pickList = new PickList();

            pickList.PickListNo        = numberControlMgr.GenerateNumber(BusinessConstants.CODE_PREFIX_PICKLIST);
            pickList.Status            = BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT;
            pickList.PickBy            = this.entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_PICK_BY).Value;
            pickList.OrderType         = orderType;
            pickList.PartyFrom         = partyFrom;
            pickList.PartyTo           = partyTo;
            pickList.ShipFrom          = shipFrom;
            pickList.ShipTo            = shipTo;
            pickList.DockDescription   = dockDescription;
            pickList.CreateDate        = dateTimeNow;
            pickList.CreateUser        = user;
            pickList.LastModifyDate    = dateTimeNow;
            pickList.LastModifyUser    = user;
            pickList.IsShipScanHu      = isShipScanHu.Value;
            pickList.IsReceiptScanHu   = isReceiptScanHu.Value;
            pickList.IsAutoReceive     = isAutoReceive.Value;
            pickList.CompleteLatency   = completeLatency;
            pickList.GoodsReceiptGapTo = grGapTo;
            pickList.AsnTemplate       = asnTemplate;
            pickList.ReceiptTemplate   = receiptTemplate;
            pickList.Flow               = flow;
            pickList.WindowTime         = windowTime.Value;
            pickList.IsAsnUniqueReceipt = isAsnUniqueReceipt.Value;

            this.CreatePickList(pickList);
            #endregion

            #region 创建捡货单明细
            int index = 0;
            IList <LocationLotDetail> locationLotDetailList         = null;
            IList <LocationLotDetail> occupiedLocationLotDetailList = null; //捡货占用库存
            for (int i = 0; i < targetOrderLocationTransactionList.Count; i++)
            {
                OrderLocationTransaction orderLocationTransaction     = targetOrderLocationTransactionList[i];                     //本次循环OrderLocationTransaction
                OrderLocationTransaction lastOrderLocationTransaction = i == 0 ? null : targetOrderLocationTransactionList[i - 1]; //上次OrderLocationTransaction
                List <PickListDetail>    pickListDetailList           = new List <PickListDetail>();                               //本次生成的PickListDetail列表

                OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                OrderHead   orderHead   = orderDetail.OrderHead;
                decimal     shipQty     = orderLocationTransaction.CurrentShipQty; //库存单位

                #region 过量拣货判断
                decimal pickedQty = 0; //其它拣货单的待拣货数量,只考虑Submit和InProcess状态
                IList <PickListDetail> pickedPickListDetailList = this.pickListDetailMgr.GetPickedPickListDetail(orderLocationTransaction.Id);
                if (pickedPickListDetailList != null && pickedPickListDetailList.Count > 0)
                {
                    foreach (PickListDetail pickListDetail in pickedPickListDetailList)
                    {
                        if (pickListDetail.PickList.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT ||
                            pickListDetail.PickList.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS)
                        {
                            pickedQty += pickListDetail.Qty;
                        }
                    }
                }

                //累计发货数量 + 待捡货数量 + 本次拣货数量 不能大于 订单数量
                if ((orderLocationTransaction.AccumulateQty.HasValue ? orderLocationTransaction.AccumulateQty.Value : 0) + shipQty + pickedQty > orderLocationTransaction.OrderedQty)
                {
                    throw new BusinessErrorException("MasterData.PickList.Error.PickExcceed", orderLocationTransaction.Item.Code);
                }
                #endregion

                //比较本次OrderLocationTransaction和上次OrderLocationTransaction,如果不相同需重新查找locationLotDetailList和重置index
                //为了处理订单合并捡货时,相同零件推荐的Hu/LotNo不重复问题
                if (lastOrderLocationTransaction == null ||
                    orderLocationTransactionComparer.Compare(lastOrderLocationTransaction, orderLocationTransaction) == -1)
                {
                    index = 0;

                    #region 零头发货选项查询待拣货列表
                    string oddShipOption = orderDetail.OddShipOption;

                    if (oddShipOption == null || oddShipOption.Trim() == string.Empty)
                    {
                        CodeMaster codeMaster = this.codeMasterMgr.GetDefaultCodeMaster(BusinessConstants.CODE_MASTER_ODD_SHIP_OPTION);

                        oddShipOption = codeMaster.Value;
                    }

                    if (oddShipOption == BusinessConstants.CODE_MASTER_ODD_SHIP_OPTION_VALUE_SHIP_FIRST)
                    {
                        //零头优先发、LotnNo先进先出、货架、包装
                        if (orderHead.IsPickFromBin)
                        {
                            locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(orderLocationTransaction.Location.Code, null, null, null, orderDetail.Item.Code, null, false, null, orderDetail.Uom.Code, new string[] { "hu.ManufactureDate;Asc", "sb.Sequence;Asc", "Qty;Asc", "Id;Asc" }, orderHead.IsPickFromBin, true, null, null, true);
                        }
                        else
                        {
                            locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(orderLocationTransaction.Location.Code, null, null, null, orderDetail.Item.Code, null, false, null, orderDetail.Uom.Code, new string[] { "hu.ManufactureDate;Asc", "Qty;Asc", "Id;Asc" }, orderHead.IsPickFromBin, false, null, null, true);
                        }
                        #region 重新排序,把零头放在前面
                        if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                        {
                            IList <LocationLotDetail> oddLocationLotDetailList   = new List <LocationLotDetail>();
                            IList <LocationLotDetail> noOddLocationLotDetailList = new List <LocationLotDetail>();
                            foreach (LocationLotDetail locationLotDetail in locationLotDetailList)
                            {
                                if (!this.locationMgr.IsHuOcuppyByPickList(locationLotDetail.Hu.HuId))
                                {
                                    if (locationLotDetail.Hu.Qty < orderDetail.UnitCount)
                                    {
                                        oddLocationLotDetailList.Add(locationLotDetail);
                                        shipQty += locationLotDetail.Qty;  //零头一定要先发走,不占用待拣货数量
                                    }
                                    else
                                    {
                                        noOddLocationLotDetailList.Add(locationLotDetail);
                                    }
                                }
                            }
                            locationLotDetailList = oddLocationLotDetailList;
                            IListHelper.AddRange <LocationLotDetail>(locationLotDetailList, noOddLocationLotDetailList);
                        }
                        #endregion
                    }
                    else if (oddShipOption == BusinessConstants.CODE_MASTER_ODD_SHIP_OPTION_VALUE_NOT_SHIP)
                    {
                        //零头不发
                        if (orderHead.IsPickFromBin)
                        {
                            locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(orderLocationTransaction.Location.Code, null, null, null, orderDetail.Item.Code, null, false, orderDetail.UnitCount, orderDetail.Uom.Code, new string[] { "hu.ManufactureDate;Asc", "sb.Sequence;Asc", "Id;Asc" }, orderHead.IsPickFromBin, true);
                        }
                        else
                        {
                            locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(orderLocationTransaction.Location.Code, null, null, null, orderDetail.Item.Code, null, false, orderDetail.UnitCount, orderDetail.Uom.Code, new string[] { "hu.ManufactureDate;Asc", "Id;Asc" }, orderHead.IsPickFromBin, false);
                        }
                    }

                    #endregion

                    IList <PickListDetail> submitPickListDetailList = this.pickListDetailMgr.GetPickListDetail(orderLocationTransaction.Location.Code, orderDetail.Item.Code, orderDetail.UnitCount, orderDetail.Uom.Code, new string[] { BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT, BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS });
                    //IList<PickListResult> inprocessPickListResultList = this.pickListResultMgr.GetPickListResult(orderLocationTransaction.Location.Code, orderDetail.Item.Code, orderDetail.UnitCount, orderDetail.Uom.Code, new string[] { BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS });

                    occupiedLocationLotDetailList = this.Convert2OccupiedLocationLotDetail(submitPickListDetailList, pickList.PickBy);
                }

                if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                {
                    PickListDetail lastestPickListDetail = null;
                    for (; index < locationLotDetailList.Count; index++)
                    {
                        LocationLotDetail locationLotDetail = locationLotDetailList[index];
                        decimal           locQty            = locationLotDetail.Qty;

                        if (pickList.PickBy == BusinessConstants.CODE_MASTER_PICKBY_HU)
                        {
                            #region  Hu捡货

                            #region 过滤掉已经被推荐的库存
                            if (occupiedLocationLotDetailList != null && occupiedLocationLotDetailList.Count > 0)
                            {
                                bool findMatch = false;
                                foreach (LocationLotDetail occupiedLocationLotDetail in occupiedLocationLotDetailList)
                                {
                                    if (occupiedLocationLotDetail.Hu.HuId == locationLotDetail.Hu.HuId)
                                    {
                                        findMatch = true;
                                        continue;
                                    }
                                }

                                if (findMatch)
                                {
                                    continue;
                                }
                            }
                            #endregion

                            shipQty -= locQty;

                            PickListDetail pickListDetail = new PickListDetail();

                            pickListDetail.PickList = pickList;
                            pickListDetail.OrderLocationTransaction = orderLocationTransaction;
                            pickListDetail.Item      = orderLocationTransaction.Item;
                            pickListDetail.UnitCount = orderDetail.UnitCount;
                            pickListDetail.Uom       = orderDetail.Uom;
                            pickListDetail.HuId      = locationLotDetail.Hu.HuId;
                            pickListDetail.LotNo     = locationLotDetail.LotNo;
                            pickListDetail.Location  = locationLotDetail.Location;
                            if (locationLotDetail.StorageBin != null)
                            {
                                pickListDetail.StorageArea = locationLotDetail.StorageBin.Area;
                                pickListDetail.StorageBin  = locationLotDetail.StorageBin;
                            }
                            pickListDetail.Qty = locQty / orderLocationTransaction.UnitQty; //订单单位
                            this.pickListDetailMgr.CreatePickListDetail(pickListDetail);
                            pickList.AddPickListDetail(pickListDetail);
                            pickListDetailList.Add(pickListDetail);

                            if (shipQty <= 0)
                            {
                                index++;
                                break;
                            }
                            #endregion
                        }
                        else if (pickList.PickBy == BusinessConstants.CODE_MASTER_PICKBY_LOTNO)
                        {
                            #region  LotNo捡货

                            #region 过滤掉已经被推荐的库存
                            if (occupiedLocationLotDetailList != null && occupiedLocationLotDetailList.Count > 0)
                            {
                                foreach (LocationLotDetail occupiedLocationLotDetail in occupiedLocationLotDetailList)
                                {
                                    if (occupiedLocationLotDetail.Item.Code == locationLotDetail.Item.Code &&
                                        occupiedLocationLotDetail.LotNo == locationLotDetail.LotNo &&
                                        occupiedLocationLotDetail.Location.Code == locationLotDetail.Location.Code &&
                                        StorageBinHelper.IsStorageBinEqual(occupiedLocationLotDetail.StorageBin, locationLotDetail.StorageBin))
                                    {
                                        if (locationLotDetail.Hu.Qty < orderDetail.UnitCount)
                                        {
                                            shipQty -= locationLotDetail.Qty;  //如果零头被占用,需要扣减发货数量
                                        }

                                        if (occupiedLocationLotDetail.Qty == 0)
                                        {
                                            continue;
                                        }

                                        if (occupiedLocationLotDetail.Qty - locQty >= 0)
                                        {
                                            occupiedLocationLotDetail.Qty -= locQty;
                                            locQty = 0;
                                            continue;
                                        }
                                        else
                                        {
                                            occupiedLocationLotDetail.Qty = 0;
                                            locQty -= occupiedLocationLotDetail.Qty;
                                            break;
                                        }
                                    }
                                }

                                if (locQty == 0)
                                {
                                    continue;
                                }
                            }
                            #endregion

                            shipQty -= locQty;

                            if (shipQty < 0)
                            {
                                locQty += shipQty;
                                shipQty = 0;
                            }

                            if (lastestPickListDetail != null &&
                                lastestPickListDetail.LotNo == locationLotDetail.LotNo &&
                                StorageBinHelper.IsStorageBinEqual(lastestPickListDetail.StorageBin, locationLotDetail.StorageBin))
                            {
                                #region 合并捡货数量
                                lastestPickListDetail.Qty += locQty / orderLocationTransaction.UnitQty; //订单单位
                                this.pickListDetailMgr.UpdatePickListDetail(lastestPickListDetail);
                                #endregion
                            }
                            else
                            {
                                #region 新增捡货明细
                                lastestPickListDetail = new PickListDetail();

                                lastestPickListDetail.PickList = pickList;
                                lastestPickListDetail.OrderLocationTransaction = orderLocationTransaction;
                                lastestPickListDetail.Item      = orderLocationTransaction.Item;
                                lastestPickListDetail.UnitCount = locationLotDetail.Hu.UnitCount;  //可能拣货的包装和订单明细包装不一致,所以使用Hu上的单包装
                                lastestPickListDetail.Uom       = orderDetail.Uom;
                                lastestPickListDetail.LotNo     = locationLotDetail.Hu.LotNo;
                                lastestPickListDetail.Location  = locationLotDetail.Location;
                                if (locationLotDetail.StorageBin != null)
                                {
                                    lastestPickListDetail.StorageArea = locationLotDetail.StorageBin.Area;
                                    lastestPickListDetail.StorageBin  = locationLotDetail.StorageBin;
                                }
                                lastestPickListDetail.Qty = locQty / orderLocationTransaction.UnitQty; //订单单位

                                this.pickListDetailMgr.CreatePickListDetail(lastestPickListDetail);
                                pickList.AddPickListDetail(lastestPickListDetail);
                                pickListDetailList.Add(lastestPickListDetail);
                                #endregion
                            }

                            if (shipQty <= 0)
                            {
                                index++;
                                break;
                            }
                            #endregion
                        }
                        else
                        {
                            throw new TechnicalException("Invalied PickBy value:" + pickList.PickBy);
                        }
                    }
                }

                //if (pickListDetailList.Count == 0)
                //{
                //    throw new BusinessErrorException("MasterData.PickList.Error.NotEnoughInventory");
                //}

                if (shipQty > 0)
                {
                    PickListDetail pickListDetail = new PickListDetail();

                    pickListDetail.PickList = pickList;
                    pickListDetail.OrderLocationTransaction = orderLocationTransaction;
                    pickListDetail.Item      = orderLocationTransaction.Item;
                    pickListDetail.UnitCount = orderDetail.UnitCount;
                    pickListDetail.Uom       = orderDetail.Uom;
                    pickListDetail.Location  = orderLocationTransaction.Location;
                    pickListDetail.Qty       = shipQty / orderLocationTransaction.UnitQty;                                        //订单单位
                    pickListDetail.Memo      = this.languageMgr.TranslateMessage("MasterData.PickList.NotEnoughInventory", user); //设置Memo为库存不足

                    pickList.AddPickListDetail(pickListDetail);

                    this.pickListDetailMgr.CreatePickListDetail(pickListDetail);
                }

                if (pickListDetailList.Count > 0 && pickList.PickBy == BusinessConstants.CODE_MASTER_PICKBY_LOTNO)
                {
                    string lotNo         = string.Empty;
                    bool   hasMultiLotNo = false;
                    foreach (PickListDetail pickListDetail in pickListDetailList)
                    {
                        if (lotNo == string.Empty)
                        {
                            lotNo = pickListDetail.LotNo;
                        }
                        else if (lotNo != pickListDetail.LotNo)
                        {
                            hasMultiLotNo = true;
                            break;
                        }
                    }

                    //设置Memo为多批号
                    if (hasMultiLotNo)
                    {
                        foreach (PickListDetail pickListDetail in pickListDetailList)
                        {
                            if (pickListDetail.Memo == null || pickListDetail.Memo.Trim() == string.Empty)
                            {
                                pickListDetail.Memo = this.languageMgr.TranslateMessage("MasterData.PickList.MultiLotNo", user);
                            }
                            else
                            {
                                pickListDetail.Memo += "; " + this.languageMgr.TranslateMessage("MasterData.PickList.MultiLotNo", user);
                            }
                            this.pickListDetailMgr.UpdatePickListDetail(pickListDetail);
                        }
                    }
                }
            }
            #endregion

            //if (pickList.PickListDetails == null || pickList.PickListDetails.Count == 0)
            //{
            //    throw new BusinessErrorException("MasterData.PickList.Error.NotEnoughInventory");
            //}

            return(pickList);
        }