Пример #1
0
        public ActionResult New()
        {
            var dt   = DateTime.Now;
            var item = new SalesOrder();

            item.PointOfSale = WebConfig.PointOfSale;

            if (item.PointOfSale == null)
            {
                return(View("InvalidPointOfSale"));
            }

            if (!CashHelpers.ValidateExchangeRate())
            {
                return(View("InvalidExchangeRate"));
            }

            // Store and Serial
            item.Store = item.PointOfSale.Store;

            try {
                item.Serial = (from x in SalesOrder.Queryable
                               where x.Store.Id == item.Store.Id
                               select x.Serial).Max() + 1;
            } catch {
                item.Serial = 1;
            }

            item.Customer     = Customer.TryFind(WebConfig.DefaultCustomer);
            item.SalesPerson  = CurrentUser.Employee;
            item.Date         = dt;
            item.PromiseDate  = dt;
            item.DueDate      = dt;
            item.Currency     = WebConfig.DefaultCurrency;
            item.ExchangeRate = CashHelpers.GetTodayDefaultExchangeRate();
            item.Terms        = item.Customer.HasCredit ? PaymentTerms.NetD : PaymentTerms.Immediate;

            item.Creator          = CurrentUser.Employee;
            item.CreationTime     = dt;
            item.Updater          = item.Creator;
            item.ModificationTime = dt;

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

            return(RedirectToAction("Edit", new {
                id = item.Id
            }));
        }
Пример #2
0
        public ActionResult New()
        {
            var dt = DateTime.Now;
            var item = new SalesOrder ();

            item.PointOfSale = WebConfig.PointOfSale;

            if (item.PointOfSale == null) {
                return View ("InvalidPointOfSale");
            }

            if (!CashHelpers.ValidateExchangeRate ()) {
                return View ("InvalidExchangeRate");
            }

            // Store and Serial
            item.Store = item.PointOfSale.Store;
            try {
                item.Serial = (from x in SalesOrder.Queryable
                           where x.Store.Id == item.Store.Id
                           select x.Serial).Max () + 1;
            } catch {
                item.Serial = 1;
            }

            item.Customer = Customer.TryFind (WebConfig.DefaultCustomer);
            item.SalesPerson = CurrentUser.Employee;
            item.Date = dt;
            item.PromiseDate = dt;
            item.Terms = PaymentTerms.Immediate;
            item.DueDate = dt;
            item.Currency = WebConfig.DefaultCurrency;
            item.ExchangeRate = CashHelpers.GetTodayDefaultExchangeRate ();

            item.Creator = CurrentUser.Employee;
            item.CreationTime = dt;
            item.Updater = item.Creator;
            item.ModificationTime = dt;

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

            return RedirectToAction ("Edit", new {
                id = item.Id
            });
        }
Пример #3
0
        public ActionResult CreateFromSalesQuote(int id)
        {
            var dt         = DateTime.Now;
            var item       = new SalesOrder();
            var salesquote = SalesQuote.Find(id);

            item.PointOfSale = WebConfig.PointOfSale;

            if (item.PointOfSale == null)
            {
                return(View("InvalidPointOfSale"));
            }

            if (!CashHelpers.ValidateExchangeRate())
            {
                return(View("InvalidExchangeRate"));
            }

            if (salesquote.IsCancelled || !salesquote.IsCompleted)
            {
                return(RedirectToAction("Index", "Quotations"));
            }

            // Store and Serial
            item.Store = item.PointOfSale.Store;

            try {
                item.Serial = (from x in SalesOrder.Queryable
                               where x.Store.Id == item.Store.Id
                               select x.Serial).Max() + 1;
            } catch {
                item.Serial = 1;
            }

            item.Customer       = salesquote.Customer;
            item.SalesPerson    = salesquote.SalesPerson;
            item.Date           = dt;
            item.PromiseDate    = dt;
            item.Terms          = salesquote.Terms;
            item.DueDate        = dt.AddDays(item.Customer.CreditDays);
            item.Currency       = salesquote.Currency;
            item.ExchangeRate   = salesquote.ExchangeRate;
            item.Contact        = salesquote.Contact;
            item.Comment        = salesquote.Comment;
            item.ShipTo         = salesquote.ShipTo;
            item.CustomerShipTo = salesquote.ShipTo == null ? "" : salesquote.ShipTo.ToString();

            item.Creator          = CurrentUser.Employee;
            item.CreationTime     = dt;
            item.Updater          = item.Creator;
            item.ModificationTime = dt;

            var details = salesquote.Details.Select(x => new SalesOrderDetail {
                Currency      = x.Currency,
                ExchangeRate  = x.ExchangeRate,
                IsTaxIncluded = x.IsTaxIncluded,
                Price         = x.Price,
                Product       = x.Product,
                ProductCode   = x.ProductCode,
                ProductName   = x.ProductName,
                Quantity      = x.Quantity,
                SalesOrder    = item,
                TaxRate       = x.TaxRate,
                Warehouse     = item.PointOfSale.Warehouse,
                Comment       = x.Comment,
                DiscountRate  = x.DiscountRate
            }).ToList();


            using (var scope = new TransactionScope()) {
                item.CreateAndFlush();
                details.ForEach(x => x.CreateAndFlush());
            }


            return(RedirectToAction("Edit", new {
                id = item.Id
            }));
        }
Пример #4
0
        public ActionResult CreateFromSalesQuote(int id)
        {
            var dt = DateTime.Now;
            var item = new SalesOrder ();
            var salesquote = SalesQuote.Find (id);

            item.PointOfSale = WebConfig.PointOfSale;

            if (item.PointOfSale == null) {
                return View ("InvalidPointOfSale");
            }

            if (!CashHelpers.ValidateExchangeRate ()) {
                return View ("InvalidExchangeRate");
            }

            // Store and Serial
            item.Store = item.PointOfSale.Store;

            try {
                item.Serial = (from x in SalesOrder.Queryable
                           where x.Store.Id == item.Store.Id
                           select x.Serial).Max () + 1;
            } catch {
                item.Serial = 1;
            }

            item.Customer = salesquote.Customer;
            item.SalesPerson = salesquote.SalesPerson;
            item.Date = dt;
            item.PromiseDate = dt;
            item.Terms = PaymentTerms.Immediate;
            item.DueDate = dt.AddDays (item.Customer.CreditDays);
            item.Currency = salesquote.Currency;
            item.ExchangeRate = salesquote.ExchangeRate;
            item.ShipTo = salesquote.ShipTo;
            item.Contact = salesquote.Contact;
            item.Comment = salesquote.Comment;

            item.Creator = CurrentUser.Employee;
            item.CreationTime = dt;
            item.Updater = item.Creator;
            item.ModificationTime = dt;

            var details = salesquote.Details.Select (x => new SalesOrderDetail {
                Currency = x.Currency,
                ExchangeRate = x.ExchangeRate,
                IsTaxIncluded = x.IsTaxIncluded,
                Price = x.Price,
                Product = x.Product,
                ProductCode = x.ProductCode,
                ProductName = x.ProductName,
                Quantity = x.Quantity,
                SalesOrder = item,
                TaxRate = x.TaxRate,
                Warehouse = item.PointOfSale.Warehouse,
                Comment = x.Comment,
                Discount = x.Discount
            }).ToList ();

            using (var scope = new TransactionScope ()) {
                item.CreateAndFlush ();
                details.ForEach (x => x.CreateAndFlush ());
            }

            return RedirectToAction ("Edit", new {
                id = item.Id
            });
        }