Пример #1
0
        public ActionResult EditDetailCurrency(int id, string value)
        {
            var          detail = PurchaseOrderDetail.Find(id);
            CurrencyCode val;
            bool         success;

            success = Enum.TryParse <CurrencyCode> (value.Trim(), out val);

            if (success)
            {
                decimal rate = CashHelpers.GetTodayExchangeRate(val);

                if (rate == 0)
                {
                    Response.StatusCode = 400;
                    return(Content(Resources.Message_InvalidExchangeRate));
                }

                detail.Currency     = val;
                detail.ExchangeRate = CashHelpers.GetTodayExchangeRate(val);

                using (var scope = new TransactionScope()) {
                    detail.Update();
                }
            }

            return(Json(new {
                id = id,
                value = detail.Currency.ToString(),
                rate = detail.ExchangeRate,
                total = detail.Total.ToString("c")
            }));
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            var item = DeliveryOrder.Find(id);

            if (item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("View", new { id = item.Id }));
            }

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

            foreach (var detail in item.Details)
            {
                if (detail.Quantity > GetRemainQuantityBySalesOrderDetail(detail.OrderDetail))
                {
                    detail.Quantity = GetRemainQuantityBySalesOrderDetail(detail.OrderDetail);
                }
            }

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

            return(View(item));
        }
Пример #3
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
            }));
        }
Пример #4
0
        public ActionResult CloseSession()
        {
            var session = GetSession();

            session.CashCounts = CashHelpers.ListDenominations();

            return(View(session));
        }
Пример #5
0
        public ActionResult SetItemPrice(int id, string value)
        {
            var     entity = SalesOrderDetail.Find(id);
            bool    success;
            decimal val;

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

            success = decimal.TryParse(value.Trim(),
                                       System.Globalization.NumberStyles.Currency,
                                       null, out val);

            if (success && entity.Price >= 0)
            {
                var price_in_list = ProductPrice.Queryable.Where(x => x.List == entity.SalesOrder.Customer.PriceList && x.Product == entity.Product).SingleOrDefault();

                if (price_in_list != null)
                {
                    var current_price = price_in_list.Value;

                    if (price_in_list.Product.Currency != entity.Currency)
                    {
                        current_price = current_price * CashHelpers.GetTodayExchangeRate(price_in_list.Product.Currency, entity.Currency);
                    }

                    if (current_price > val)
                    {
                        Response.StatusCode = 400;
                        return(Content(Resources.Validation_WrongDiscount));
                    }
                }

                entity.Price = val;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = entity.Id,
                discount_percentage = entity.FormattedValueFor(x => x.DiscountRate),
                discount_price = string.Format("{0:C}", entity.Price * entity.DiscountRate),
                value = entity.FormattedValueFor(x => x.Price),
                total = entity.FormattedValueFor(x => x.Total),
                total2 = entity.FormattedValueFor(x => x.TotalEx)
            }));
        }
Пример #6
0
        public ActionResult Index()
        {
            if (!CashHelpers.ValidateExchangeRate())
            {
                return(View("InvalidExchangeRate"));
            }

            var search = SearchPurchaseOrders(new Search <PurchaseOrder> {
                Limit = WebConfig.PageSize
            });

            return(View(search));
        }
Пример #7
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
            }));
        }
Пример #8
0
        public ActionResult SetCurrency(int id, string value)
        {
            var          entity = SalesQuote.Find(id);
            CurrencyCode val;
            bool         success;

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

            success = Enum.TryParse <CurrencyCode> (value.Trim(), out val);

            if (success)
            {
                decimal rate = CashHelpers.GetTodayExchangeRate(val);

                if (rate == 0m)
                {
                    Response.StatusCode = 400;
                    return(Content(Resources.Message_InvalidExchangeRate));
                }

                entity.Currency         = val;
                entity.ExchangeRate     = rate;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    foreach (var item in entity.Details)
                    {
                        item.Currency     = val;
                        item.ExchangeRate = rate;
                        item.Update();
                    }

                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = entity.Id,
                value = entity.FormattedValueFor(x => x.Currency),
                rate = entity.FormattedValueFor(x => x.ExchangeRate),
                itemsChanged = success
            }));
        }
Пример #9
0
        public ActionResult Edit(int id)
        {
            var item = SalesQuote.Find(id);

            if (item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("View", new {
                    id = item.Id
                }));
            }

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

            return(View(item));
        }
Пример #10
0
        public ActionResult Edit(int id)
        {
            var item = SpecialReceipt.Find(id);

            if (item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("View", new { id = item.Id }));
            }

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

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

            return(View(item));
        }
Пример #11
0
        public ActionResult OpenSession()
        {
            if (GetSession() != null)
            {
                return(RedirectToAction("Index"));
            }

            var model = new CashSession {
                Start      = DateTime.Now,
                CashCounts = CashHelpers.ListDenominations(),
                CashDrawer = WebConfig.CashDrawer,
                Cashier    = CurrentUser.Employee
            };

            if (model.CashDrawer == null)
            {
                return(View("InvalidCashDrawer"));
            }

            return(View(model));
        }
Пример #12
0
        public ViewResult Index()
        {
            if (WebConfig.Store == null)
            {
                return(View("InvalidStore"));
            }

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

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

            var search = SearchSalesQuotes(new Search <SalesQuote> {
                Limit = WebConfig.PageSize
            });

            return(View(search));
        }
Пример #13
0
        public ActionResult Edit(int id)
        {
            var item = PurchaseOrder.Find(id);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_MasterEditView", item));
            }

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

            if (item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("Details", new {
                    id = item.Id
                }));
            }

            return(View(item));
        }
Пример #14
0
        public ActionResult AddItem(int order, int product)
        {
            var entity = SalesQuote.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 SalesQuoteDetail {
                SalesQuote    = entity,
                Product       = p,
                ProductCode   = p.Code,
                ProductName   = p.Name,
                TaxRate       = p.TaxRate,
                IsTaxIncluded = p.IsTaxIncluded,
                Quantity      = p.MinimumOrderQuantity,
                Price         = price.Value,
                DiscountRate  = discount,
                Currency      = entity.Currency,
                ExchangeRate  = entity.ExchangeRate
            };

            if (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
            }));
        }
Пример #15
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
            }));
        }