public static BeymenSAPResult ReportItemsToSAP(BeymenSAPRequest request)
        {
            if (request == null)
            {
                return null;
            }
            BeymenSAPService.Beymen_eCommClient beymenService = new BeymenSAPService.Beymen_eCommClient();
            var urunler = MapVariantInfoListToUrunList(request.VariantInfoList);
            BeymenSAPResult result = new BeymenSAPResult();
            result.CollectionLocationCode = request.CollectionLocationCode;
            result.IdempotencyKey = request.IdempotencyKey;
            result.PackagingLocationCode = request.PackagingLocationCode;
            try
            {
                try
                {
                    string waybillNumber = beymenService.UrunToplama(request.IdempotencyKey, request.CollectionLocationCode, request.PackagingLocationCode, request.Status, urunler);
                    
                    result.WaybillNumber = waybillNumber;
                }
                catch (TimeoutException e)
                {
                    result.IsTimeout = true;
                    result.ErrorMessage = "Sistem cevap vermiyor.";
                }
            }
            catch (Exception e)
            {
                result.ErrorMessage = e.Message;
            }

            return result;
        }
        public static BeymenSAPResult ReportItemsToSAP(BeymenSAPRequest request)
        {
            bool isSuccess = Random.Next(1, 5) != 2;

            BeymenSAPResult result = new BeymenSAPResult
            {
                IdempotencyKey = request.IdempotencyKey,
                PackagingLocationCode = request.PackagingLocationCode,
                ErrorMessage = isSuccess ? null : "Hata-" + request.IdempotencyKey,
                WaybillNumber = isSuccess?"Test-Waybil-" + request.IdempotencyKey:null,
                CollectionLocationCode = request.CollectionLocationCode
            };
            return result;
        }
        private static void ReportItemsToBeymenPrepareResult(BeymenSAPRequest request, List<CollectionTrasnferResultData> resultList, List<vCollectionOrderItem> itemList, string status)
        {
            try
            {
                BeymenSAPResult result = BeymenSAPServiceWrapper.ReportItemsToSAP(request);

                CollectionTrasnferResultData resultData = new CollectionTrasnferResultData();
                resultData.IdempotencyKey = request.IdempotencyKey;
                resultData.OrderItemIdList = itemList.Select(x => x.OrderItemID).ToList();
                resultData.ErrorMessage = result.ErrorMessage;
                resultData.WaybillNumber = result.WaybillNumber;
                resultData.IsSuccess = result.IsSuccess;
                resultData.Status = status;
                resultData.IsTimeout = result.IsTimeout;
                resultData.CollectionDataID = itemList.First().CollectionDataID;
                resultData.WaybillNumber = result.WaybillNumber;
                resultList.Add(resultData);
            }
            catch (Exception e)
            {
                ErrorSignal.FromCurrentContext().Raise(e);
            }
        }
        private static List<CollectionTrasnferResultData> ReportItems(List<vCollectionOrderItem> collectionItemList)
        {
            //varyant, durum ve lokasyonlara göre gruplama yapılır. Beymenden istenen data bu şekilde.
            var groupedFoundList = (from i in collectionItemList
                                    group i by new { i.PackagingLocationCode, i.StatusCode, i.CollectionLocationCode } into g
                                    select new
                                    {
                                        PackagingLocationCode = g.Key.PackagingLocationCode,
                                        Status = g.Key.StatusCode,
                                        CollectionLocationCode = g.Key.CollectionLocationCode,
                                        ItemList = g
                                    });
            List<CollectionTrasnferResultData> resultList = new List<CollectionTrasnferResultData>();

            foreach (var item in groupedFoundList)
            {
                List<vCollectionOrderItem> itemList = item.ItemList.Select(x => x).ToList();
                string idemPotencyKey = Guid.NewGuid().ToString();
                if (itemList.Count > 0)
                {
                    if (string.IsNullOrEmpty(itemList.First().IdempotencyKey) == false)
                    {
                        idemPotencyKey = itemList.First().IdempotencyKey;
                    }
                }

                BeymenSAPRequest request = new BeymenSAPRequest();
                request.IdempotencyKey = idemPotencyKey;
                request.PackagingLocationCode = item.PackagingLocationCode;
                request.CollectionLocationCode = item.CollectionLocationCode;

                //Bulunamayan itemlar gruplanıp gönderiliyor.
                if (item.Status == OrderItemStatus.NotFound.ToString())
                {
                    var notFoundBaseSubGroupedItemList = (from i in item.ItemList
                                                          group i by i.NotFountReasonExternalSystemCode.Value into g
                                                          select new { NotFoundReasonID = g.Key, NotFoundItemList = g.ToList() }).ToList();

                    foreach (var notfoundBaseList in notFoundBaseSubGroupedItemList)
                    {
                        if (notfoundBaseList.NotFoundItemList.Count <= 0)
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(notfoundBaseList.NotFoundItemList.First().IdempotencyKey) == false)
                        {
                            request.IdempotencyKey = itemList.First().IdempotencyKey;
                        }
                        List<VariantInfo> notFounVariantInfoList = (from v in itemList
                                                                    group v by v.VariantCode into g
                                                                    select new VariantInfo
                                                                    {
                                                                        VariantCode = g.Key,
                                                                        Quantity = g.Count(),
                                                                        NotFoundReason = notfoundBaseList.NotFoundReasonID
                                                                    }).ToList();
                        request.VariantInfoList = notFounVariantInfoList;
                        request.Status = GetStatus(OrderItemStatus.NotFound.ToString());

                        ReportItemsToBeymenPrepareResult(request, resultList, itemList, OrderItemStatus.NotFound.ToString());
                    }
                    continue;
                }

                List<VariantInfo> variantInfoList = (from v in itemList
                                                     group v by v.VariantCode into g
                                                     select new VariantInfo
                                                     {
                                                         VariantCode = g.Key,
                                                         Quantity = g.Count(),
                                                         NotFoundReason = 0
                                                     }).ToList();
                request.VariantInfoList = variantInfoList;
                request.Status = GetStatus(OrderItemStatus.Found.ToString());

                ReportItemsToBeymenPrepareResult(request, resultList, itemList, OrderItemStatus.Found.ToString());
            }

            return resultList;
        }