예제 #1
0
        public ActionResult AddItem(int order, int product)
        {
            var entity = SalesOrder.TryFind (order);
            var p = Product.TryFind (product);
            int pl = entity.Customer.PriceList.Id;
            var cost = (from x in ProductPrice.Queryable
                    where x.Product.Id == product && x.List.Id == 0
                    select x).SingleOrDefault ();
            var price = (from x in ProductPrice.Queryable
                     where x.Product.Id == product && x.List.Id == pl
                     select x).SingleOrDefault ();

            if (entity.IsCompleted || entity.IsCancelled) {
                Response.StatusCode = 400;
                return Content (Resources.ItemAlreadyCompletedOrCancelled);
            }

            if (cost == null) {
                cost = new ProductPrice {
                    Value = decimal.Zero
                };
            }

            if (price == null) {
                price = new ProductPrice {
                    Value = decimal.MaxValue
                };
            }

            var item = new SalesOrderDetail {
                SalesOrder = entity,
                Product = p,
                Warehouse = entity.PointOfSale.Warehouse,
                ProductCode = p.Code,
                ProductName = p.Name,
                TaxRate = p.TaxRate,
                IsTaxIncluded = p.IsTaxIncluded,
                Quantity = p.MinimumOrderQuantity,
                Cost = cost.Value,
                Price = price.Value,
                Currency = entity.Currency,
                ExchangeRate = entity.ExchangeRate
            };

            if (p.Currency != entity.Currency) {
                item.Cost = cost.Value * CashHelpers.GetTodayExchangeRate (p.Currency, entity.Currency);
                item.Price = price.Value * CashHelpers.GetTodayExchangeRate (p.Currency, entity.Currency);
            }

            using (var scope = new TransactionScope ()) {
                item.CreateAndFlush ();
            }

            return Json (new {
                id = item.Id
            });
        }
예제 #2
0
        public ActionResult AddItem(int order, int product)
        {
            var entity = SalesOrder.TryFind(order);
            var p      = Product.TryFind(product);
            int pl     = entity.Customer.PriceList.Id;
            var cost   = (from x in ProductPrice.Queryable
                          where x.Product.Id == product && x.List.Id == 0
                          select x).SingleOrDefault();
            var price = (from x in ProductPrice.Queryable
                         where x.Product.Id == product && x.List.Id == pl
                         select x).SingleOrDefault();
            var discount = (from x in CustomerDiscount.Queryable
                            where x.Product.Id == product && x.Customer.Id == entity.Customer.Id
                            select x.Discount).SingleOrDefault();

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (cost == null)
            {
                cost = new ProductPrice {
                    Value = decimal.Zero
                };
            }

            if (price == null)
            {
                price = new ProductPrice {
                    Value = decimal.MaxValue
                };
            }

            var item = new SalesOrderDetail {
                SalesOrder    = entity,
                Product       = p,
                Warehouse     = entity.PointOfSale.Warehouse,
                ProductCode   = p.Code,
                ProductName   = p.Name,
                TaxRate       = p.TaxRate,
                IsTaxIncluded = p.IsTaxIncluded,
                Quantity      = p.MinimumOrderQuantity,
                Cost          = cost.Value,
                Price         = price.Value,
                DiscountRate  = discount,
                Currency      = entity.Currency,
                ExchangeRate  = entity.ExchangeRate,
                Comment       = p.Comment
            };

            if (p.Currency != entity.Currency)
            {
                item.Cost  = cost.Value * CashHelpers.GetTodayExchangeRate(p.Currency, entity.Currency);
                item.Price = price.Value * CashHelpers.GetTodayExchangeRate(p.Currency, entity.Currency);
            }

            using (var scope = new TransactionScope()) {
                item.CreateAndFlush();
            }

            return(Json(new {
                id = item.Id
            }));
        }