예제 #1
0
        public async Task Given_Products_WhenOrderWithLinesIsCreated_Total_MakesSense()
        {
            var(aRef, bRef) = await Given(async session =>
            {
                var productA = new Product();
                var productB = new Product();
                return(await session.Save(productB), await session.Save(productA));
            });

            var orderRef = await When(async session =>
            {
                var productA = await session.Resolve(aRef);
                var productB = await session.Resolve(bRef);

                var salesOrder = new SalesOrder("123");
                salesOrder.AddLine(productA, 5);
                salesOrder.AddLine(productB, 3, 3);

                return(await session.Save(salesOrder));
            });

            await Then(async session =>
            {
                var order = await session.Resolve(orderRef);

                Assert.That(order.Total, Is.EqualTo(14));

                var orders = await session
                             .Query <SalesOrder>()
                             .Where(o => o.Total > 10)
                             .ToListAsync();

                Assert.That(orders.Count, Is.EqualTo(1));
            });
        }
        /**
         * Adds a `SalesOrderLine` to a `SalesOrder` object and populates it.
         * Note:
         * If the given `SalesOrderItem.ForFreight` property is 1, the amount is
         * is added to `SalesOrder.Freight` and no `SalesOrderLine` is added.
         * If the given `SalesOrderItem.ForHandling` property is 1, no `SalesOrderLine`
         * is added to the `SalesOrderLine`.
         */
        private void AddLine(SalesOrder salesOrder, SalesOrderItem line)
        {
            if (line.ForFreight == 1)
            {
                salesOrder.FreightAmount = line.Amount;
            }
            else if (line.ForHandling != 1)
            {
                var _             = salesOrder.AddLine();
                var itemReference = GetItemEntityReference(line.ItemCode);
                if (itemReference == null)
                {
                    Logger.Debug("Item {@name} was not found in Sage.", line.ItemCode);
                    Logger.Debug("Item {@name} needs to be created in Sage", line.ItemCode);
                    return;
                }

                var item = LoadInventoryItem(itemReference);
                _.AccountReference       = GetSalesAccountReference(item);
                _.Quantity               = line.Qty;
                _.Description            = GetLineDescription(line);
                _.UnitPrice              = Decimal.Divide(line.Amount, line.Qty); // _.CalculateUnitCost(_.Quantity, _.Amount);
                _.Amount                 = _.CalculateAmount(_.Quantity, _.UnitPrice);
                _.InventoryItemReference = itemReference;
            }
        }
        public Task AddLine(AddSalesOrderLineMessage message)
        {
            var line = new SalesOrderLine(message.ProductKey, message.Quantity, message.Price, message.Comment);

            _salesOrder.AddLine(line);

            return(TaskDone.Done);
        }
예제 #4
0
            public override async Task <Reference <SalesOrder> > Handle(CreateSalesOrder command, CancellationToken cancellationToken)
            {
                var order = new SalesOrder(this.orderNumberSequence.Next().ToString());

                foreach (var l in command.Lines)
                {
                    var product = await this.Session.Resolve(l.ProductRef);

                    order.AddLine(product, l.Price, l.Quantity);
                }

                return(await this.Session.Save(order));
            }
예제 #5
0
        public static SO_OrderBatch ReadXML(string fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Orders));
            Orders        oOrders    = new Orders();

            using (FileStream fs = new FileStream(fileName, FileMode.Open))
            {
                oOrders = (Orders)serializer.Deserialize(fs);
            }

            SO_OrderBatch batch = new SO_OrderBatch();

            foreach (Order xmlorder in oOrders.Items)
            {
                SalesOrder order = new SalesOrder();
                order.RequiredDate = DateUtils.DateUtils.ShipDate(DateTime.Today, 5);

                order.ShipToName     = xmlorder.ShippingFullName;
                order.ShipToAddress1 = xmlorder.ShippingAddress1;
                order.ShipToAddress2 = xmlorder.ShippingAddress2;
                order.ShipToZipcode  = xmlorder.ShippingPostCode;

                order.CustomerNo   = xmlorder.Customer_Number;
                order.CustomerPONo = "Website-" + xmlorder.OrderId;

                order.BillToCompany = xmlorder.BillingCompany;

                foreach (OrderLineItems xmlline in xmlorder.Items)
                {
                    order.AddLine(new LineItem(xmlline.SKU, xmlline.Quantity, xmlline.Meta));
                }

                batch.AddOrder(order);
            }

            return(batch);
        }