Beispiel #1
0
        public IActionResult AddOrder([FromBody] OrderFormDto orderFormDto)
        {
            var userId   = _userManager.GetUserIdAsInt(User);
            var orderDto = _orderAppService.Add(userId, orderFormDto);

            return(StatusCode(StatusCodes.Status201Created, orderDto));
        }
Beispiel #2
0
        public OrderDto Add(int userId, OrderFormDto orderFormDto)
        {
            var order = _mapper.Map <Order>(orderFormDto);

            order.Send(new OrderRoute(userId, userId, order.Id, string.Empty));

            _orderRepository.Add(order);
            _unitOfWork.Complete();

            order = _orderRepository.GetById(order.Id);

            return(_mapper.Map <OrderDto>(order));
        }
Beispiel #3
0
        public void ValidateWallet_SellHasNotInstrument_Failed()
        {
            var form = new OrderFormDto()
            {
                Ticker = "test", Volumen = 100, OrderType = OrderType.Sell
            };
            var wallet = new Wallet()
            {
                Assets = new List <BaseAsset>()
                {
                }
            };
            var result = EntryOrderValidator.ValidateWallet(form, wallet);

            Assert.IsFalse(result);
        }
Beispiel #4
0
        public void ValidateWallet_BuyNotEnaughCash_Failed()
        {
            var form = new OrderFormDto()
            {
                Price = 100f, Volumen = 100, OrderType = OrderType.Buy
            };
            var wallet = new Wallet()
            {
                CirculatingMedium = new Cash()
                {
                    AvailableAmount = 999M
                }
            };

            var result = EntryOrderValidator.ValidateWallet(form, wallet);

            Assert.IsFalse(result);
        }
Beispiel #5
0
        public void ValidateWallet_BuyExactliCash_succes()
        {
            var form = new OrderFormDto()
            {
                Price = 100f, Volumen = 100, OrderType = OrderType.Buy
            };
            var wallet = new Wallet()
            {
                CirculatingMedium = new Cash()
                {
                    AvailableAmount = 10000M
                }
            };

            var result = EntryOrderValidator.ValidateWallet(form, wallet);

            Assert.IsTrue(result);
        }
Beispiel #6
0
        public void ValidateWallet_SellHasInstrument_succes()
        {
            var form = new OrderFormDto()
            {
                Ticker = "test", Volumen = 100, OrderType = OrderType.Sell
            };
            var wallet = new Wallet()
            {
                Assets = new List <BaseAsset>()
                {
                    new BaseAsset()
                    {
                        Name = "test", Volumen = 100
                    }
                }
            };
            var result = EntryOrderValidator.ValidateWallet(form, wallet);

            Assert.IsTrue(result);
        }
Beispiel #7
0
        private bool ProcessOrderFile(IServiceProvider serviceProvider, string fileName, string fileContent)
        {
            IWarehousesService         warehousesService         = serviceProvider.GetService <IWarehousesService>();
            IShippingWarehousesService shippingWarehousesService = serviceProvider.GetService <IShippingWarehousesService>();
            IOrdersService             ordersService             = serviceProvider.GetService <IOrdersService>();

            // Загружаем данные из файла
            XmlDocument doc = new XmlDocument();

            using (StringReader reader = new StringReader(fileContent))
            {
                doc.Load(reader);
            }

            var docRoots = doc.SelectNodes("//IDOC");

            int totalCount     = docRoots.Count;
            int processedCount = 0;

            var orders = new List <OrderFormDto>();

            foreach (XmlNode docRoot in docRoots)
            {
                ++processedCount;

                string       orderNumber = docRoot.SelectSingleNode("E1EDK02[QUALF='002']/BELNR")?.InnerText?.TrimStart('0');
                OrderFormDto dto         = ordersService.GetFormByNumber(orderNumber);
                bool         isNew       = dto == null;
                if (dto == null)
                {
                    dto = new OrderFormDto();
                }

                dto.AdditionalInfo = $"INJECTION - {fileName}";

                decimal weightUomCoeff = docRoot.ParseUom("E1EDK01/GEWEI", new[] { "GRM", "GR", "KGM", "KG" }, new[] { 0.001M, 0.001M, 1M, 1M }, 1);

                string soldTo = docRoot.SelectSingleNode("E1EDKA1[PARVW='AG']/PARTN")?.InnerText?.TrimStart('0');

                dto.OrderNumber             = new LookUpDto(orderNumber);
                dto.OrderDate               = docRoot.ParseDateTime("E1EDK02[QUALF='001']/DATUM")?.ToString("dd.MM.yyyy") ?? dto.OrderDate;
                dto.WeightKg                = docRoot.ParseDecimal("E1EDK01/BRGEW").ApplyDecimalUowCoeff(weightUomCoeff) ?? dto.WeightKg;
                dto.BoxesCount              = docRoot.ParseDecimal("E1EDK01/Y0126SD_ORDERS05_TMS_01/YYCAR_H") ?? dto.BoxesCount;
                dto.DeliveryDate            = docRoot.ParseDateTime("E1EDK03[IDDAT='002']/DATUM")?.ToString("dd.MM.yyyy") ?? dto.DeliveryDate;
                dto.OrderAmountExcludingVAT = docRoot.ParseDecimal("E1EDS01[SUMID='002']/SUMME") ?? dto.OrderAmountExcludingVAT;

                string shippingAddressCode = docRoot.SelectSingleNode("E1EDP01/WERKS")?.InnerText;
                var    shippingWarehouse   = shippingWarehousesService.GetByCode(shippingAddressCode);
                dto.ShippingAddress     = shippingWarehouse?.Address ?? dto.ShippingAddress;
                dto.ShippingCity        = string.IsNullOrEmpty(shippingWarehouse?.City) ? dto.ShippingCity : new LookUpDto(shippingWarehouse.City);
                dto.ShippingWarehouseId = shippingWarehouse?.Id == null ? dto.ShippingWarehouseId : new LookUpDto(shippingWarehouse.Id.ToString(), shippingWarehouse.WarehouseName);

                dto.DeliveryAddress = null;
                dto.DeliveryCity    = null;
                dto.DeliveryRegion  = null;
                dto.PickingTypeId   = null;
                dto.TransitDays     = null;
                dto.DeliveryType    = null;

                if (isNew)
                {
                    dto.ClientOrderNumber = docRoot.SelectSingleNode("E1EDK02[QUALF='001']/BELNR")?.InnerText ?? dto.ClientOrderNumber;
                    dto.Payer             = docRoot.SelectSingleNode("E1EDKA1[PARVW='RG']/PARTN")?.InnerText?.TrimStart('0') ?? dto.Payer;
                }

                if (isNew || dto.ManualPalletsCount != true)
                {
                    dto.PalletsCount = docRoot.ParseInt("E1EDK01/Y0126SD_ORDERS05_TMS_01/YYPAL_H") ?? dto.PalletsCount;
                }

                IEnumerable <string> missedRequiredFields = ValidateRequiredFields(dto);
                if (missedRequiredFields.Any())
                {
                    string fields = string.Join(", ", missedRequiredFields);
                    Log.Error("В файле {fileName} отсутствуют следующие обязательные поля: {fields}. Заказ ({processedCount}/{totalCount}) не создан.",
                              fileName, fields, processedCount, totalCount);
                }
                else
                {
                    int entryInd  = 0;
                    var itemRoots = docRoot.SelectNodes("E1EDP01");
                    dto.Items = dto.Items ?? new List <OrderItemDto>();
                    var updatedItems = new HashSet <string>();
                    foreach (XmlNode itemRoot in itemRoots)
                    {
                        ++entryInd;

                        string posex    = itemRoot.SelectSingleNode("POSEX")?.InnerText ?? string.Empty;
                        int    posexNum = -1;
                        int.TryParse(posex.TrimStart('0'), out posexNum);
                        if ((posexNum % 10) != 0)
                        {
                            continue;
                        }

                        string nart = itemRoot.SelectSingleNode("E1EDP19/IDTNR")?.InnerText?.TrimStart('0');
                        if (string.IsNullOrEmpty(nart))
                        {
                            Log.Warning("Пустое значение NART в позиции #{entryInd} заказа ({processedCount}/{totalCount}) из файла {fileName}, пропуск.",
                                        entryInd, processedCount, totalCount, fileName);
                            continue;
                        }

                        int?quantity = itemRoot.ParseInt("MENGE");
                        if (quantity == null || quantity == 0)
                        {
                            Log.Warning("Пустое количество в позиции #{entryInd} заказа ({processedCount}/{totalCount}) из файла {fileName}, пропуск.",
                                        entryInd, processedCount, totalCount, fileName);
                            continue;
                        }

                        OrderItemDto itemDto = dto.Items.Where(i => i.Nart == nart).FirstOrDefault();

                        if (itemDto == null)
                        {
                            itemDto = new OrderItemDto();
                            dto.Items.Add(itemDto);
                        }
                        else
                        {
                            updatedItems.Add(itemDto.Id);
                        }

                        itemDto.Nart     = nart;
                        itemDto.Quantity = quantity ?? itemDto.Quantity;
                    }

                    var itemsToRemove = dto.Items.Where(x => !string.IsNullOrEmpty(x.Id) && !updatedItems.Contains(x.Id)).ToList();
                    itemsToRemove.ForEach(x => dto.Items.Remove(x));

                    if (isNew)
                    {
                        Log.Information("Создан новый заказ {OrderNumber} ({processedCount}/{totalCount}) на основании файла {fileName}.",
                                        dto.OrderNumber, processedCount, totalCount, fileName);
                    }
                    else
                    {
                        Log.Information("Обновлен заказ {OrderNumber} ({processedCount}/{totalCount}) на основании файла {fileName}.",
                                        dto.OrderNumber, processedCount, totalCount, fileName);
                    }

                    orders.Add(dto);
                }
            }

            bool isSuccess = orders.Any();

            if (isSuccess)
            {
                ordersService.Import(orders);
            }

            return(isSuccess);
        }
Beispiel #8
0
        public void CheckFormDataSemantic_Incorect_Failed(OrderFormDto form)
        {
            var result = EntryOrderValidator.CheckFormDataSemantic(form);

            Assert.IsFalse(result, $"Incorect form was accepted : {form.Ticker}");
        }
Beispiel #9
0
        public void CheckFormDataSemantic_Correct_Succes(OrderFormDto form)
        {
            var result = EntryOrderValidator.CheckFormDataSemantic(form);

            Assert.IsTrue(result, $"correct form was rejected : {form.Ticker}");
        }
Beispiel #10
0
        public void CheckFormDatacompleteness_IncorectData_shouldFailed(OrderFormDto form)
        {
            var result = EntryOrderValidator.CheckFormDataCompleteness(form);

            Assert.IsFalse(result, $"Incorect form was accepted : {form.Ticker}");
        }
Beispiel #11
0
        public void CheckFormDatacompleteness_CorrectData_shouldSucces(OrderFormDto form)
        {
            var result = EntryOrderValidator.CheckFormDataCompleteness(form);

            Assert.IsTrue(result, $"correct form was rejected : {form.Ticker}");
        }