Ejemplo n.º 1
0
        public virtual ActionResult Confirm(int id)
        {
            var entity = SalesOrder.TryFind(id);

            if (entity == null || entity.IsCompleted || entity.IsCancelled)
            {
                return(RedirectToAction("Index"));
            }

            entity.Updater          = CurrentUser.Employee;
            entity.ModificationTime = DateTime.Now;
            entity.IsDelivered      = false;
            entity.IsCompleted      = true;

            foreach (var detail in entity.Details)
            {
                if (detail.Price == decimal.Zero)
                {
                    return(View("ZeroPriceError", entity));
                }
            }

            if (entity.ShipTo == null)
            {
                //entity.IsDelivered = true;
                using (var scope = new TransactionScope()) {
                    var warehouse = entity.PointOfSale.Warehouse;
                    var dt        = DateTime.Now;

                    foreach (var x in entity.Details)
                    {
                        x.Warehouse = warehouse;
                        x.Update();

                        InventoryHelpers.ChangeNotification(TransactionType.SalesOrder, entity.Id,
                                                            dt, warehouse, null, x.Product, -x.Quantity);
                    }

                    entity.UpdateAndFlush();
                }
            }
            else
            {
                DeliveryOrder deliver = new DeliveryOrder();

                deliver.Date         = DateTime.Now;
                deliver.CreationTime = DateTime.Now;
                deliver.Creator      = CurrentUser.Employee;
                deliver.Updater      = entity.Creator;

                deliver.Customer = entity.Customer;
                deliver.ShipTo   = entity.ShipTo;
                deliver.Store    = entity.Store;

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

                foreach (var detail in entity.Details)
                {
                    var detaild = (new DeliveryOrderDetail {
                        DeliveryOrder = deliver,
                        OrderDetail = detail,
                        Quantity = detail.Quantity,
                        ProductName = detail.ProductName,
                        Product = detail.Product,
                        ProductCode = detail.ProductCode
                    });
                    using (var scope = new TransactionScope()) {
                        detaild.CreateAndFlush();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult New(DeliveryOrder item)
        {
            item.Customer = Customer.TryFind (WebConfig.DefaultCustomer);

            if (!ModelState.IsValid) {
                return PartialView ("_Create", item);
            }

            item.Store = WebConfig.Store;

            item.Serial = 0;
            item.Date = DateTime.Now;
            item.CreationTime = DateTime.Now;
            item.Creator = CurrentUser.Employee;
            item.ModificationTime = item.CreationTime;
            item.Updater = item.Creator;

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

            return RedirectToAction ("Edit", new { id = item.Id });
        }
Ejemplo n.º 3
0
        public ActionResult New(string value)
        {
            int        id     = 0;
            SalesOrder entity = null;

            if (int.TryParse(value, out id))
            {
                entity = SalesOrder.TryFind(id);
            }

            if (entity == null)
            {
                Response.StatusCode = 400;
                return(Content(Resources.SalesOrderNotFound));
            }

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

            //if (entity.ShipTo == null) {
            //	Response.StatusCode = 400;
            //	return Content (Resources.ShipToRequired);
            //}

            if (entity.Store != WebConfig.Store)
            {
                Response.StatusCode = 400;
                return(Content(Resources.InvalidStore));
            }

            DeliveryOrder item = new DeliveryOrder();

            item.Customer = Customer.TryFind(WebConfig.DefaultCustomer);

            if (!ModelState.IsValid)
            {
                return(PartialView("_Create", item));
            }

            item.Store = WebConfig.Store;

            item.Serial           = 0;
            item.Date             = DateTime.Now;
            item.CreationTime     = DateTime.Now;
            item.Creator          = CurrentUser.Employee;
            item.ModificationTime = item.CreationTime;
            item.Updater          = item.Creator;
            item.Customer         = entity.Customer;
            item.ShipTo           = entity.ShipTo;
            item.Comment          = entity.Comment;


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

                foreach (var detail in entity.Details.Where(x => GetRemainQuantityBySalesOrderDetail(x) > 0.0m))
                {
                    var deliverydetail = new DeliveryOrderDetail {
                        DeliveryOrder = item,
                        OrderDetail   = detail,
                        Product       = detail.Product,
                        ProductCode   = detail.ProductCode,
                        ProductName   = detail.ProductName,
                        Quantity      = detail.Quantity
                    };
                    deliverydetail.CreateAndFlush();
                }
            }

            return(Json(new { url = Url.Action("Edit", new { id = item.Id }) }));
        }