예제 #1
0
        private async Task UpsertSalesOrderDetail(string orderID)
        {
            var order = await _oc.Orders.GetAsync <HSOrder>(OrderDirection.Incoming, orderID);

            var brand = await _oc.Buyers.GetAsync <HSBuyer>(order.FromCompanyID);

            var promos = await _oc.Orders.ListPromotionsAsync(OrderDirection.Incoming, orderID);

            var cosmosSalesOrder = new OrderDetailData()
            {
                PartitionKey = "PartitionValue",
                OrderID      = orderID,
                Data         = order,
                BrandName    = brand.Name
            };

            if (promos.Items.Count > 0)
            {
                cosmosSalesOrder.Promos = ReportPromoBuilder.BuildPromoFields(promos, ReportTypeEnum.SalesOrderDetail);
            }

            var queryable = _salesOrderDetailDataRepo.GetQueryable().Where(order => order.PartitionKey == "PartitionValue");

            var requestOptions = BuildQueryRequestOptions();

            var listOptions = BuildListOptions(orderID);

            CosmosListPage <OrderDetailData> currentOrderListPage = await _salesOrderDetailDataRepo.GetItemsAsync(queryable, requestOptions, listOptions);

            var cosmosID = "";

            if (currentOrderListPage.Items.Count() == 1)
            {
                cosmosID = cosmosSalesOrder.id = currentOrderListPage.Items[0].id;
            }

            await _salesOrderDetailDataRepo.UpsertItemAsync(cosmosID, cosmosSalesOrder);
        }
예제 #2
0
        private async Task UpsertPurchaseOrderDetail(string orderID)
        {
            var orders = await _oc.Orders.ListAllAsync <HSOrder>(OrderDirection.Outgoing, filters : $"ID={orderID}-*");

            var queryable = _purchaseOrderDetailDataRepo.GetQueryable().Where(order => order.PartitionKey == "PartitionValue");

            var requestOptions = BuildQueryRequestOptions();

            var salesOrderWorksheet = await _oc.IntegrationEvents.GetWorksheetAsync <HSOrderWorksheet>(OrderDirection.Incoming, orderID);

            var promos = await _oc.Orders.ListPromotionsAsync(OrderDirection.Incoming, salesOrderWorksheet.Order.ID);

            var discountedLineItems = new List <HSLineItem>();

            if (promos.Items.Count() > 0)
            {
                var discountedLineFilter = new Dictionary <string, object>
                {
                    ["PromotionDiscount"] = ">0"
                };

                discountedLineItems = await _oc.LineItems.ListAllAsync <HSLineItem>(OrderDirection.Incoming, salesOrderWorksheet.Order.ID, filters : discountedLineFilter);
            }

            foreach (var order in orders)
            {
                order.FromUser = salesOrderWorksheet.Order.FromUser;

                order.BillingAddress = new HSAddressBuyer()
                {
                    xp = new BuyerAddressXP()
                    {
                        LocationID = salesOrderWorksheet?.Order?.BillingAddress?.xp?.LocationID
                    }
                };

                var brand = await _oc.Buyers.GetAsync <HSBuyer>(salesOrderWorksheet.Order.FromCompanyID);

                var supplier = await _oc.Suppliers.GetAsync <HSSupplier>(order.ToCompanyID);

                order.ShippingCost = GetPurchaseOrderShippingCost(salesOrderWorksheet, order.ToCompanyID);
                if (salesOrderWorksheet.Order.PromotionDiscount > 0)
                {
                    order.PromotionDiscount = GetPurchaseOrderPromotionDiscount(salesOrderWorksheet, order.ToCompanyID);
                }

                var cosmosPurchaseOrder = new OrderDetailData()
                {
                    PartitionKey = "PartitionValue",
                    OrderID      = order.ID,
                    Data         = order,
                    SupplierName = supplier.Name,
                    BrandName    = brand.Name,
                };

                if (promos.Items.Count > 0)
                {
                    cosmosPurchaseOrder.Promos = ReportPromoBuilder.BuildPromoFields(promos, ReportTypeEnum.PurchaseOrderDetail, order.ToCompanyID, discountedLineItems);
                }

                var listOptions = BuildListOptions(order.ID);

                CosmosListPage <OrderDetailData> currentOrderListPage = await _purchaseOrderDetailDataRepo.GetItemsAsync(queryable, requestOptions, listOptions);

                var cosmosID = "";
                if (currentOrderListPage.Items.Count() == 1)
                {
                    cosmosID = cosmosPurchaseOrder.id = currentOrderListPage.Items[0].id;
                }

                await _purchaseOrderDetailDataRepo.UpsertItemAsync(cosmosID, cosmosPurchaseOrder);
            }
        }