예제 #1
0
        public ActionResult Delete(int id)
        {
            var model = new ImportList();

            model.Current = new ImportRecord();
            var unremovable = ImexItem.Unremovable(UserID, Employee.ID, DbAction.Import.Remove, id);

            if (unremovable.Count > 0)
            {
                model.Message = "Số lượng sản phẩm tồn kho ít hơn số lượng sản phẩm phiếu xuất";
            }
            else
            {
                model.Result  = Import.Remove(UserID, Employee.ID, id, true);
                model.Message = model.Result ? "Xóa phiếu thành công" : "Xóa phiếu không thành công";
            }
            if (!model.Result)
            {
                model.Current = Import.Get(UserID, Employee.ID, id);
            }
            model.List = SKtimeManagement.Import.History(UserID, Employee.ID, Employee.BussinessID);
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.HistoryPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.History, model));
        }
예제 #2
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));
        }
예제 #3
0
 public Export(string employeeName, List <WarehouseInfo> warehouses, int?toWarehouseID = null, string status = ExportStatus.Pending, int warehouseID = 0, ImexItem[] selected = null, string note = "", string message = "", bool result = false) : base()
 {
     EmployeeName = employeeName;
     WarehouseID  = warehouseID;
     if (warehouseID == 0 && warehouses.Count >= 1)
     {
         WarehouseID = warehouses.FirstOrDefault().ID;
     }
     ToWarehouseID = toWarehouseID;
     Data          = new List <ImexItem>();
     Warehouses    = warehouses;
     if (selected == null)
     {
         Selected = new ImexItem[] { }
     }
     ;
     else
     {
         Selected = selected;
     }
     Note    = note;
     Message = message;
     Result  = result;
     Filter  = new ProductFilter();
     Status  = status;
 }
예제 #4
0
        public ActionResult ProductList(ProductFilter filter)
        {
            var data = ImexItem.FindAll(UserID, Employee.ID, filter.Action, Employee.BussinessID, filter);

            return(Json(new
            {
                result = true,
                html = RenderPartialViewToString(Views.Selector, data)
            }, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public static List <ImexItem> Read(int userID, int employeeID, FileInfo fileInfo, int bussinessID, int warehouseID, bool getDbPrice = false)
        {
            var          result = new List <ImexItem>();
            HSSFWorkbook hssfwb;

            using (FileStream file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read))
            {
                hssfwb = new HSSFWorkbook(file);
            }

            var sheet = hssfwb.GetSheetAt(0);

            if (sheet.LastRowNum > 0)
            {
                for (var i = 1; i <= sheet.LastRowNum; i++)
                {
                    var row = sheet.GetRow(i);
                    try
                    {
                        var item = new ImexItem();
                        item.Code        = row.GetCellValue <string>(0);
                        item.WarehouseID = warehouseID;
                        //item.WarehouseName = row.GetCellValue<string>(1);
                        item.Price    = row.GetCellValue <decimal>(2);
                        item.Quantity = row.GetCellValue <int>(3);
                        result.Add(item);
                    }
                    catch { }
                }
            }

            if (result.Count > 0)
            {
                var dbItems = ImexItem.Get(userID, employeeID, warehouseID, result);
                foreach (var dbItem in dbItems)
                {
                    var item = result.FirstOrDefault(i => i.Code == dbItem.Code && i.WarehouseID == dbItem.WarehouseID);
                    item.ID          = dbItem.ID;
                    item.Code        = dbItem.Code;
                    item.Name        = dbItem.Name;
                    item.Image       = dbItem.Image;
                    item.WarehouseID = dbItem.WarehouseID;
                    item.Maximum     = dbItem.Quantity;
                    item.Point       = dbItem.Point;
                    if (getDbPrice)
                    {
                        item.Price = dbItem.Price;
                    }
                }
            }
            return(result);
        }
예제 #6
0
        public ActionResult Remove(int id, int whid)
        {
            var list = SessionValue <List <ImexItem> >(SessionKey.ImportList);

            if (list == null)
            {
                list = new List <ImexItem>();
            }
            list.Remove(list.FirstOrDefault(i => i.ID == id && i.WarehouseID == whid));
            Session[SessionKey.ImportList] = list;
            return(Json(new
            {
                data = ImexItem.ToJson(list)
            }, JsonRequestBehavior.DenyGet));
        }
예제 #7
0
        public ActionResult Add(int id, int subID)
        {
            var product = ImexItem.Get(UserID, Employee.ID, DbAction.Order.View, id, subID);

            product.Quantity = 1;
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    result = true,
                    html = RenderPartialViewToString(Views.List, product)
                }, JsonRequestBehavior.AllowGet));
            }
            return(RedirectToAction("Create"));
        }
예제 #8
0
        public ActionResult Remove(int id, int whid)
        {
            var list = SessionValue <List <ImexItem> >(SessionKey.ExportList);

            if (list == null)
            {
                list = new List <ImexItem>();
            }
            list.Remove(list.FirstOrDefault(i => i.ID == id && i.WarehouseID == whid));
            Session[SessionKey.ExportList] = list;
            return(Json(new
            {
                data = ImexItem.ToJson(list),
                total = list.Sum(i => i.Quantity * i.Price).GetCurrencyString()
            }, JsonRequestBehavior.DenyGet));
        }
예제 #9
0
 public Export(List <WarehouseInfo> warehouses, OrderRecord record, bool editable = false, string message = "", bool result = false)
 {
     ID           = record.ID;
     Code         = record.Code;
     EmployeeID   = record.EmployeeID;
     EmployeeName = record.EmployeeName;
     WarehouseID  = record.WarehouseID;
     if (record.WarehouseID == 0 && warehouses.Count >= 1)
     {
         WarehouseID = warehouses.FirstOrDefault().ID;
     }
     Warehouses    = warehouses;
     ClientID      = record.ClientID;
     ClientCode    = record.ClientCode;
     ClientName    = record.ClientName;
     ClientPhone   = record.ClientPhone;
     ClientAddress = record.ClientAddress;
     ClientType    = record.ClientType;
     DiscountType  = record.DiscountType;
     DiscountValue = record.DiscountValue;
     DeliveryID    = record.DeliveryID;
     OrderReceipt  = record.Receipt;
     PayMethod     = record.PayMethod;
     ToExport      = record.ToExport;
     Discount      = record.Discount;
     Paid          = record.Paid;
     Data          = new List <ImexItem>();
     if (record.Items == null)
     {
         Selected = new ImexItem[] { }
     }
     ;
     else
     {
         Selected = record.Items;
     }
     Note     = record.Note;
     Status   = record.Status;
     Return   = record.Return;
     Message  = message;
     Result   = result;
     Editable = editable;
     Filter   = new ProductFilter();
 }
예제 #10
0
 public Import(string employeeName, List <WarehouseInfo> warehouses, int?warehouseID = null, ImexItem[] selected = null, string note = "", string message = "") : base()
 {
     EmployeeName      = employeeName;
     Warehouses        = warehouses;
     SelectedWarehouse = warehouseID;
     if (warehouseID == 0 && warehouses.Count >= 1)
     {
         SelectedWarehouse = warehouses.FirstOrDefault().ID;
     }
     Data = new List <ImexItem>();
     if (selected == null)
     {
         Selected = new ImexItem[] { }
     }
     ;
     else
     {
         Selected = selected;
     }
     Note    = note;
     Message = message;
     Filter  = new ProductFilter();
 }
예제 #11
0
        public ActionResult UploadFile(int id)
        {
            var list    = new List <ImexItem>();
            var result  = false;
            var message = "";

            foreach (string f in Request.Files)
            {
                var fileContent = Request.Files[f];
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    // get a stream
                    var      stream   = fileContent.InputStream;
                    var      fileName = String.Format("{1}_{0}", Path.GetFileName(fileContent.FileName), DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));
                    FileInfo fileInfo;
                    FileManagement.SaveFile("Import/Import", fileName, stream, out fileInfo);
                    list = ImexItem.Read(UserID, Employee.ID, fileInfo, Employee.BussinessID);
                    var unavailable = list.Count(i => i.ID <= 0 || i.WarehouseID <= 0);
                    if (unavailable > 0)
                    {
                        message = String.Format("{0} sản phẩm không tìm thấy", unavailable);
                    }
                    else
                    {
                        message = "Nhập sản phẩn từ file thành công";
                        result  = true;
                    }
                }
                break;
            }
            return(Json(new
            {
                result = result,
                list = ImexItem.ToJson(list.Where(i => i.ID > 0 && i.WarehouseID > 0)),
                message = message
            }, JsonRequestBehavior.DenyGet));
        }
예제 #12
0
        public static List <ImexItem> Read(int userID, int employeeID, FileInfo fileInfo, int bussinessID)
        {
            var          result = new List <ImexItem>();
            HSSFWorkbook hssfwb;

            using (FileStream file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read))
            {
                hssfwb = new HSSFWorkbook(file);
            }

            var sheet = hssfwb.GetSheetAt(0);

            if (sheet.LastRowNum > 0)
            {
                var whs = new List <string>();
                for (var i = 1; i <= sheet.LastRowNum; i++)
                {
                    var row = sheet.GetRow(i);
                    try
                    {
                        var wh = row.GetCellValue <string>(2);
                        if (!String.IsNullOrEmpty(wh) && !whs.Contains(wh))
                        {
                            whs.Add(wh);
                        }
                        var item = new ImexItem();
                        item.Code = row.GetCellValue <string>(0);
                        //item.WarehouseID = warehouseID;
                        item.WarehouseName = wh;
                        item.Price         = row.GetCellValue <decimal>(3);
                        item.Quantity      = row.GetCellValue <int>(4);
                        result.Add(item);
                    }
                    catch { }
                }
                var warehouses = WarehouseInfo.Find(userID, employeeID, whs);
                foreach (var item in result)
                {
                    if (warehouses.FirstOrDefault(i => i.Name == item.WarehouseName) != null)
                    {
                        item.WarehouseID = warehouses.FirstOrDefault(i => i.Name == item.WarehouseName).ID;
                    }
                }
                if (result.Count > 0)
                {
                    var dbItems = ImexItem.Get(userID, employeeID, result);
                    foreach (var dbItem in dbItems)
                    {
                        foreach (var item in result.Where(i => i.Code == dbItem.Code))
                        {
                            item.ID    = dbItem.ID;
                            item.Code  = dbItem.Code;
                            item.Name  = dbItem.Name;
                            item.Price = dbItem.Price;
                            //item.Quantity = 1;
                        }
                    }
                }
                result = result.Where(i => i.ID > 0 && i.WarehouseID > 0).ToList();
            }
            return(result);
        }
예제 #13
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));
            }
        }
예제 #14
0
        public ActionResult Submit(int id, int warehouseID, int?toWarehouseID, ImexItem[] items, string note, string status)
        {
            var action      = id > 0 ? DbAction.Export.Modify : DbAction.Export.Create;
            var unavailable = ImexItem.Unavailable(UserID, Employee.ID, warehouseID, action, items, 0, id);
            var exportID    = 0;
            var message     = "";
            var result      = false;
            var login       = Login.Get(UserID);

            if (id > 0 && login.Username != "admin" && login.Type != LoginType.Office)
            {
                message = "Bạn không có quyền cập nhật phiếu xuất";
            }
            else 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 (toWarehouseID.HasValue && toWarehouseID.Value == warehouseID)
            {
                message = "Kho nhận trùng kho xuất";
            }
            else
            {
                message = "Lưu thông tin không thành công";
                if (items != null && items.Length > 0)
                {
                    if ((exportID = SKtimeManagement.Export.Submit(id, UserID, Employee.ID, Employee.BussinessID, warehouseID, toWarehouseID, status, items, note)) > 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)
            {
                var model = new ExportList();
                model.List    = Export.History(UserID, Employee.ID, Employee.BussinessID);
                model.Current = Export.GetExport(UserID, Employee.ID, exportID);
                foreach (var product in model.Current.Products)
                {
                    product.ProductUrl = RenderPartialViewToString("ProductUrl", product);
                }
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.HistoryPartial, model)
                    }, JsonRequestBehavior.DenyGet));
                }
                return(RedirectToAction(Views.History));
            }
            else
            {
                var model = new Export(Employee.Name,
                                       WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Export.View),
                                       toWarehouseID, status, warehouseID, items, note, message, result);
                model.ID       = id;
                model.Editable = login.Username == "admin";
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.ExportPartial, model)
                    }, JsonRequestBehavior.DenyGet));
                }
                return(RedirectToAction(Views.Export));
            }
        }