Exemple #1
0
        public JsonResult AddPurchaseDetail(int movement, int warehouse, int product)
        {
            var p    = Product.Find(product);
            var cost = (from x in ProductPrice.Queryable
                        where x.Product.Id == product && x.List.Id == 0
                        select x.Value).SingleOrDefault();

            var item = new PurchaseOrderDetail {
                Order         = PurchaseOrder.Find(movement),
                Warehouse     = Warehouse.Find(warehouse),
                Product       = p,
                ProductCode   = p.Code,
                ProductName   = p.Name,
                Quantity      = 1,
                TaxRate       = p.TaxRate,
                IsTaxIncluded = p.IsTaxIncluded,
                DiscountRate  = 0,
                Price         = cost,
                ExchangeRate  = CashHelpers.GetTodayDefaultExchangeRate(),
                Currency      = WebConfig.DefaultCurrency
            };

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

            return(Json(new {
                id = item.Id
            }));
        }
        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
            }));
        }