예제 #1
0
        public ActionResult Exchange(int id)
        {
            var login  = Login.Get(UserID);
            var record = new OrderRecord(Export.GetOrder(UserID, Employee.ID, id), true);
            var model  = new Export(
                WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Order.View),
                record,
                login.Username == "admin")
            {
                Return = true
            };

            if (Request.IsAjaxRequest())
            {
                using (var data = new DataClassesDataContext())
                {
                    model.Action = "Exchange";
                    model.TotalTransactionPaid = data.GetTotalTransactionPaid(id).SingleOrDefault().Paid;
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.ExportPartial, model)
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            return(View(Views.Export, model));
        }
예제 #2
0
        public ActionResult AuthorizedWarehouse()
        {
            var list = WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Login.View);

            return(Json(new
            {
                id = list.Select(l => l.ID).ToArray(),
                name = list.Select(l => l.Name).ToArray(),
            }, JsonRequestBehavior.DenyGet));
        }
예제 #3
0
        public ActionResult FindDownload(int warehouseID, int?tagID, FindItem[] items)
        {
            var result = false;

            try
            {
                var filter = new ProductFilter()
                {
                    WarehouseID = warehouseID,
                    TagID       = tagID
                };
                var products = ProductInfo.FindAll(UserID, Employee.ID, Employee.BussinessID, "", filter, true, null);
                var model    = new FindList(filter);
                model.Warehouses = WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Product.View);
                var warehouse = model.Warehouses.FirstOrDefault(i => i.ID == warehouseID);
                if (products.Data.Count > 0 && warehouse != null)
                {
                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            var product = products.Data.FirstOrDefault(i => i.Code == item.Code);
                            if (product == null)
                            {
                                product = ProductInfo.FindList(UserID, Employee.BussinessID, Employee.BussinessID, new ProductFilter()
                                {
                                    Code = item.Code
                                }, false, 100, DbAction.Product.View).FirstOrDefault();
                                model.Data.Add(new FindItem(item.Code, warehouse.Name, item.Quantity, product));
                            }
                            else
                            {
                                model.Data.Add(new FindItem(product, item.Quantity));
                            }
                        }
                    }
                    model.Data.AddRange(products.Data.Where(i => model.Data.FirstOrDefault(d => d.Code == i.Code) == null).Select(i => new FindItem(i)));
                }
                var fileName = String.Format("Products_{0}.xls", DateTime.Now.ToString("ddMMyyyyHHmmss"));
                var file     = String.Format("{0}/Content/Download/{1}", SiteConfiguration.ApplicationPath, fileName);
                Functions.CheckDirectory(String.Format("{0}/Content/Download/", SiteConfiguration.ApplicationPath));
                SaveFind(file, model);
                Session[SessionKey.Download] = fileName;
                result = true;
            }
            catch { }
            return(Json(new
            {
                result = result
            }, JsonRequestBehavior.DenyGet));
        }
예제 #4
0
        public ActionResult Create()
        {
            var model = new Import(Employee.Name,
                                   WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Import.View));

            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ImportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Import, model));
        }
예제 #5
0
        public ActionResult Check(ProductFilter filter)
        {
            var data = ProductInfo.Check(UserID, Employee.ID, Employee.BussinessID, filter, null);

            data.Warehouses = WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Product.View);
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.CheckPartial, data)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Check, data));
        }
예제 #6
0
        public ActionResult Find()
        {
            var data = new FindList();

            data.Warehouses = WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Product.View);
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.FindPartial, data)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Find, data));
        }
예제 #7
0
        public ActionResult CreateFromExport(int id)
        {
            var record = Export.GetExport(UserID, Employee.ID, id);
            var model  = new Import(Employee.Name,
                                    WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Import.View), selected: record.Products.Select(i => new ImexItem(i, record.WarehouseID, record.WarehouseName)).ToArray());

            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ImportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Import, model));
        }
예제 #8
0
        public ActionResult Create()
        {
            var login = Login.Get(UserID);
            var model = new Export(Employee.Name,
                                   WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Export.View));

            model.Editable = login.Username == "admin";
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ExportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Export, model));
        }
예제 #9
0
        public ActionResult Update(int id)
        {
            var login = Login.Get(UserID);
            var model = new Export(
                WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Order.View),
                new OrderRecord(Export.GetOrder(UserID, Employee.ID, id)),
                login.Username == "admin");

            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ExportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Export, model));
        }
예제 #10
0
        public ActionResult FindFinish(int warehouseID, int?tagID, FindItem[] items)
        {
            var filter = new ProductFilter()
            {
                WarehouseID = warehouseID,
                TagID       = tagID
            };
            var products = ProductInfo.FindAll(UserID, Employee.ID, Employee.BussinessID, "", filter, true, null);
            var model    = new FindList(filter);

            model.Warehouses = WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Product.View);
            var warehouse = model.Warehouses.FirstOrDefault(i => i.ID == warehouseID);

            if (products.Data.Count > 0 && warehouse != null)
            {
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var product = products.Data.FirstOrDefault(i => i.Code == item.Code);
                        if (product == null)
                        {
                            product = ProductInfo.FindList(UserID, Employee.BussinessID, Employee.BussinessID, new ProductFilter()
                            {
                                Code = item.Code
                            }, false, 100, DbAction.Product.View).FirstOrDefault();
                            model.Data.Add(new FindItem(item.Code, warehouse.Name, item.Quantity, product));
                        }
                        else
                        {
                            model.Data.Add(new FindItem(product, item.Quantity));
                        }
                    }
                }
                model.Data.AddRange(products.Data.Where(i => model.Data.FirstOrDefault(d => d.Code == i.Code) == null).Select(i => new FindItem(i)));
            }
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.FindPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Find, model));
        }
예제 #11
0
        public ActionResult Update(int id)
        {
            var record = Export.GetExport(UserID, Employee.ID, id);
            var login  = Login.Get(UserID);
            var model  = new Export(record.EmployeeName,
                                    WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Export.View),
                                    record.ToWarehouseID, record.Status, record.WarehouseID, record.Products.Select(p => new ImexItem(p)).ToArray(), record.Note, "", record.Result);

            model.ID       = record.ID;
            model.Code     = record.Code;
            model.Editable = login.Username == "admin";
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ExportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Export, model));
        }
예제 #12
0
        private void UpdateTemplate(string fileName)
        {
            var warehouses = WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Import.View);

            if (warehouses.Count > 0)
            {
                HSSFWorkbook hssfwb;
                using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    hssfwb = new HSSFWorkbook(file);
                }

                var sheet    = hssfwb.GetSheetAt(0);
                var rowCount = sheet.LastRowNum;
                for (var i = 1; i <= rowCount; i++)
                {
                    var row = sheet.GetRow(i);
                    if (row.Cells.FirstOrDefault(c => c.ColumnIndex == 10) != null)
                    {
                        row.Cells.FirstOrDefault(c => c.ColumnIndex == 10).SetCellValue("");
                    }
                }
                for (var i = 0; i < warehouses.Count; i++)
                {
                    if (i + 1 > rowCount)
                    {
                        sheet.CreateRow(i + 1);
                    }
                    var row = sheet.GetRow(i + 1);
                    if (row.Cells.FirstOrDefault(c => c.ColumnIndex == 10) == null)
                    {
                        row.CreateCell(10);
                    }
                    row.Cells.FirstOrDefault(c => c.ColumnIndex == 10).SetCellValue(warehouses[i].Name);
                }
                using (var fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    hssfwb.Write(fs);
                }
            }
        }
예제 #13
0
        public ActionResult Update(int id)
        {
            var record = Import.Get(UserID, Employee.ID, id);
            var model  = new Import(record.EmployeeName,
                                    WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Import.View),
                                    record.WarehouseID, record.Products.ToArray(), record.Note)
            {
                Receipt = record.Receipt
            };

            model.ID   = record.ID;
            model.Code = record.Code;
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ImportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Import, model));
        }
예제 #14
0
        public ActionResult Submit(int id, ImexItem[] items, string note, string receipt)
        {
            var action      = id > 0 ? DbAction.Import.Modify : DbAction.Import.Create;
            var message     = "";
            int?recordID    = null;
            int warehouseID = 0;

            if (id > 0 && !EmployeeInfo.IsAdmin(UserID, Employee.ID, Employee.ID, action))
            {
                message = "Bạn không có quyền sử dụng chức năng này";
            }
            else
            {
                message = "Lưu thông tin không thành công";
                if (items != null && items.Length > 0)
                {
                    var warehouses = items.GroupBy(i => i.WarehouseID);
                    foreach (var warehouse in warehouses)
                    {
                        recordID    = SKtimeManagement.Import.Submit(id, UserID, Employee.ID, Employee.BussinessID, warehouse.Key, warehouse.ToArray(), note, receipt);
                        warehouseID = warehouse.Key;
                    }
                    if (recordID.HasValue)
                    {
                        message = "Lưu thông tin thành công";
                    }
                }
                else
                {
                    message = "Không có sản phẩm được chọn";
                }
            }
            if (!recordID.HasValue)
            {
                var model = new Import(Employee.Name,
                                       WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Import.View),
                                       warehouseID, items, note, message)
                {
                    Receipt = receipt
                };
                model.ID = id;
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.ImportPartial, model)
                    }, JsonRequestBehavior.DenyGet));
                }
                return(View(Views.Import, model));
            }
            else
            {
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        result = true,
                        redirect = Url.Action("Detail", "Import", new { id = recordID.Value })
                    }, JsonRequestBehavior.DenyGet));
                }
                return(RedirectToAction(Views.Detail, new { id = recordID.Value }));
            }
        }
예제 #15
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));
            }
        }
예제 #16
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));
            }
        }