Example #1
0
        public ActionResult Remove(int id)
        {
            var products = ImexItem.Find(UserID, Employee.ID, DbAction.Product.View, Employee.BussinessID, new ProductFilter()
            {
                ProductID = id
            });
            var message = "";

            if (products.FirstOrDefault(i => i.Quantity > 0) != null)
            {
                message = "Sản phẩm vẫn còn tồn";
            }
            else if (ProductInfo.Remove(UserID, Employee.ID, id))
            {
                message = "Xóa thông tin thành công";
            }
            var model = ProductInfo.Find(UserID, Employee.ID, Employee.BussinessID, message);

            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ListPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.List, model));
        }
Example #2
0
        public ActionResult ProductList(ProductFilter filter)
        {
            var data = ImexItem.Find(UserID, Employee.ID, filter.Action, Employee.BussinessID, filter);

            return(Json(new
            {
                result = true,
                html = RenderPartialViewToString(Views.Selector, data)
            }, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult Submit(OrderRecord record, FormCollection collection)
        {
            record.EmployeeName = Employee.Name;
            var action      = record.ID > 0 ? DbAction.Order.Modify : DbAction.Order.Create;
            var unavailable = ImexItem.Unavailable(UserID, Employee.ID, record.WarehouseID, action, record.Items, record.ID);
            var orderID     = 0;
            var message     = "";
            var result      = false;
            var login       = Login.Get(UserID);

            //if (record.ID > 0 && login.Username != "admin" && login.Type != LoginType.Office)
            //    message = "Bạn không có quyền cập nhật hóa đơn";
            if (unavailable.Count > 0)
            {
                message = String.Format("Số lượng vượt mức tồn kho:<br/>{0}", String.Join("<br/>", unavailable.Select(i => i.Name)));
            }
            else if (record.ClientID == 0 && (String.IsNullOrEmpty(record.ClientName) || String.IsNullOrEmpty(record.ClientPhone)))
            {
                message = "Thiếu thông tin khách hàng (tên, số điện thoại)";
            }
            else if (record.Items.Sum(i => i.Quantity * i.Price) - record.Discount - record.Paid != 0)
            {
                message = "Tổng tiền khuyến mãi và đã trả không bằng tổng tiền hóa đơn";
            }
            else
            {
                message = "Lưu thông tin không thành công";
                if (record.Items != null && record.Items.Length > 0)
                {
                    if (login.Username != "admin" && record.ID == 0)
                    {
                        record.SubmitDate = DateTime.Now;
                    }
                    if (login.Username != "admin")
                    {
                        record.NewEmployeeID = null;
                    }
                    if ((orderID = SKtimeManagement.Export.SaveOrder(UserID, Employee.ID, Employee.BussinessID, record)) > 0)
                    {
                        message = "Lưu thông tin thành công";
                        result  = true;
                    }
                }
                else
                {
                    message = "Không có sản phẩm được chọn";
                }
            }
            if (result)
            {
                // trigger creating income when do exchange product on order
                if (collection["Action"] == "Exchange")
                {
                    using (var data = new DataClassesDataContext())
                    {
                        data.TriggerInsertIncome(record.ID, Employee.ID, Employee.BussinessID, record.WarehouseID, record.Code, BaseModel.NewUniqueCode(UserID, Employee.ID, Employee.BussinessID, "Income"), DateTime.Now, Convert.ToDecimal(collection["TotalTransactionPaid"]));
                    }
                }

                var model = new ExportList();
                model.List    = Export.OrderHistory(UserID, Employee.ID, Employee.BussinessID);
                model.Current = Export.GetOrder(UserID, Employee.ID, orderID);
                foreach (var product in model.Current.Products)
                {
                    product.ProductUrl = RenderPartialViewToString("ProductUrl", product);
                }
                foreach (var product in model.Current.ReturnProducts)
                {
                    product.ProductUrl = RenderPartialViewToString("ProductUrl", product);
                }
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.HistoryPartial, model)
                    }, JsonRequestBehavior.DenyGet));
                }
                return(RedirectToAction(Views.History));
            }
            else
            {
                var data  = ImexItem.Find(UserID, Employee.ID, action, Employee.BussinessID);
                var model = new Export(
                    WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Order.View),
                    record, login.Username == "admin", message, result);
                if (record.Return)
                {
                    var returnRecord = new OrderRecord(Export.GetOrder(UserID, Employee.ID, record.ID), true);
                    var items        = model.Selected.ToList();
                    items.AddRange(returnRecord.Items);
                    model.Selected = items.ToArray();
                }
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.ExportPartial, model)
                    }, JsonRequestBehavior.DenyGet));
                }
                return(RedirectToAction(Views.Export));
            }
        }