Exemple #1
0
        public ActionResult List(ProductFilter filter)
        {
            var data = ProductInfo.Find(UserID, Employee.ID, Employee.BussinessID, "", filter, true, null);

            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    result = true,
                    html = RenderPartialViewToString(Views.ListPartial, data)
                }, JsonRequestBehavior.DenyGet));
            }
            return(View(Views.List, data));
        }
Exemple #2
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));
        }
Exemple #3
0
        public static ProductPartReport Get(int userID, int bussinessID, ProductFilter filter = null)
        {
            var result = new ProductPartReport(filter);

            try
            {
                var conditions = new List <string>();
                if (filter != null)
                {
                    if (!String.IsNullOrEmpty(filter.Code))
                    {
                        conditions.Add(String.Format("and p.Code like N'%{0}%'", filter.Code));
                    }
                    if (!String.IsNullOrEmpty(filter.Name))
                    {
                        conditions.Add(String.Format("and p.Name like N'%{0}%'", filter.Name));
                    }
                }
                var query = String.Format(
                    @"select p.*, t.ID as [TagID], t.Name as [TagName], s.Name as [SupplierName],
                        (select isnull(sum(ep.Quantity), 0) from ExportProduct ep join Export e on ep.ExportID = e.ID 
                        join Warranty r on ep.WarrantyID = r.ID and r.Status = 'active' {3} {4}
                        where ep.ProductID = p.ID and ep.WarrantyID is not null and 
                        ((select Username from Login where ID = {2}) = 'admin' or e.WarehouseID in (select WarehouseID from LoginWarehouse where LoginID = {2}))) +
                        (select isnull(sum(ep.Quantity), 0) from ExportProduct ep join Export e on ep.ExportID = e.ID 
                        join Repair r on ep.RepairID = r.ID and r.Status = 'active' {3} {4}
                        where ep.ProductID = p.ID and ep.RepairID is not null and 
                        ((select Username from Login where ID = {2}) = 'admin' or e.WarehouseID in (select WarehouseID from LoginWarehouse where LoginID = {2})))
                        as [Quantity]
                    from Product p
                        left join Supplier s on p.SupplierID = s.ID
                        join ProductTag pt on p.ID = pt.ProductID and pt.TagID = (select top 1 TagID from ProductTag where ProductID = p.ID order by TagID desc)
                        join Tag t on pt.TagID = t.ID and t.Status = 'active' and t.ForRepair = 1
                    where p.Status = 'active' and p.BussinessID = {0} {1} order by Name",
                    bussinessID, String.Join(" ", conditions), userID,
                    filter != null && filter.From.HasValue ? String.Format(" and r.SubmitDate >= {0}", filter.From.DbValue()) : "",
                    filter != null && filter.To.HasValue ? String.Format(" and r.SubmitDate <= {0}", filter.To.DbValue()) : "");
                using (var con = Repo.DB.SKtimeManagement)
                {
                    result.Data = con.Query <ProductInfo>(query).ToList();
                }
            }
            catch { }
            return(result);
        }
Exemple #4
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));
        }
Exemple #5
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();
 }
Exemple #6
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();
 }
Exemple #7
0
        public ActionResult Download(ProductFilter filter)
        {
            var result = false;

            try
            {
                var data = ProductInfo.FindAll(UserID, Employee.ID, Employee.BussinessID, "", filter, true, null);
                if (data != null)
                {
                    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));
                    SaveDownload(file, data.Data);
                    Session[SessionKey.Download] = fileName;
                    result = true;
                }
            }
            catch { }
            return(Json(new
            {
                result = result
            }, JsonRequestBehavior.DenyGet));
        }
Exemple #8
0
 public ProductPartReport(ProductFilter filter = null)
 {
     Filter = filter != null ? filter : new ProductFilter();
 }
Exemple #9
0
        public static List <ImexItem> Find(int userID, int employeeID, string action, int bussinessID, ProductFilter filter = null, bool log = false)
        {
            QueryOutput queryResult;
            var         conditions = new List <string>();

            if (filter != null)
            {
                if (filter.ProductID.HasValue)
                {
                    conditions.Add(String.Format("and p.ID = {0}", filter.ProductID.Value));
                }
                if (!String.IsNullOrEmpty(filter.Code))
                {
                    conditions.Add(String.Format("and p.Code like N'%{0}%'", filter.Code));
                }
                if (!String.IsNullOrEmpty(filter.Name))
                {
                    conditions.Add(String.Format("and p.Name like N'%{0}%'", filter.Name));
                }
                if (filter.SupplierID.HasValue)
                {
                    conditions.Add(String.Format("and p.SupplierID = {0}", filter.SupplierID.DbValue()));
                }
                if (filter.WarehouseID.HasValue && filter.WarehouseID > 0)
                {
                    conditions.Add(String.Format("and w.ID = {0}", filter.WarehouseID.DbValue()));
                }
            }
            var strSql = String.Format(
                @"select top 100 p.ID, p.Code, p.Name, p.Image, p.Price, p.Point, w.Name as [WarehouseName], w.ID as [WarehouseID],
                    sum(isnull(ip.Quantity, 0)) - isnull((select sum(ep.Quantity) from ExportProduct ep left join Export e on e.ID = ep.ExportID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') where ep.Returned = 0 and ep.ProductID = p.ID and e.WarehouseID = w.ID), 0) as [Quantity]
                from Product p
                    join ImportProduct ip on p.ID = ip.ProductID
                    join Import i on i.ID = ip.ImportID and i.Status = 'active' 
                    join Warehouse w on w.Status = 'active' and w.ID = i.WarehouseID {2} {3}
                where p.Status = 'active' and p.BussinessID = {0} {1} 
                group by p.ID, p.Code, p.Name, p.Image, p.Price, p.Point, w.Name, w.ID
                having sum(isnull(ip.Quantity, 0)) - isnull((select sum(ep.Quantity) from ExportProduct ep left join Export e on e.ID = ep.ExportID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') where ep.Returned = 0 and ep.ProductID = p.ID and e.WarehouseID = w.ID), 0) > 0
                order by p.Name",
                bussinessID, String.Join(" ", conditions),
                filter != null && filter.TagID.HasValue ? String.Format("join ProductTag pt on p.ID = pt.ProductID and pt.TagID = {0}", filter.TagID.Value) : "",
                filter != null && filter.ForRepair.HasValue ? String.Format("join ProductTag pt on p.ID = pt.ProductID join Tag t on t.ID = pt.TagID and t.ForRepair = {0}", filter.ForRepair.DbValue()) : "");
            var products = Query <ImexItem>(new DbQuery(userID, employeeID, action,
                                                        strSql, log), out queryResult);

            return(products.Select(i => i.SetMaximum()).ToList());
        }
Exemple #10
0
        public static List <ImexItem> FindAll(int userID, int employeeID, string action, int bussinessID, ProductFilter filter = null, bool log = false)
        {
            QueryOutput queryResult;
            var         conditions = new List <string>();

            if (filter != null)
            {
                if (!String.IsNullOrEmpty(filter.Code))
                {
                    conditions.Add(String.Format("and p.Code like N'%{0}%'", filter.Code));
                }
                if (!String.IsNullOrEmpty(filter.Name))
                {
                    conditions.Add(String.Format("and p.Name like N'%{0}%'", filter.Name));
                }
                if (filter.SupplierID.HasValue)
                {
                    conditions.Add(String.Format("and p.SupplierID = {0}", filter.SupplierID.DbValue()));
                }
            }
            var strSql = String.Format(@"select top 100 p.ID, p.Code, p.Name, p.Image, p.Price, p.Point, {3} as [WarehouseID]
                from Product p {2}
                where p.Status = 'active' and p.BussinessID = {0} {1} order by p.Name",
                                       bussinessID, String.Join(" ", conditions),
                                       filter != null && filter.TagID.HasValue ? String.Format("join ProductTag pt on p.ID = pt.ProductID and pt.TagID = {0}", filter.TagID.Value) : "",
                                       filter != null && filter.WarehouseID.HasValue ? filter.WarehouseID.Value : 0);

            return(Query <ImexItem>(new DbQuery(userID, employeeID, action,
                                                strSql, log), out queryResult));
        }
Exemple #11
0
 public FindList(ProductFilter filter = null)
 {
     Data   = new List <FindItem>();
     Tags   = new List <TagInfo>();
     Filter = filter != null ? filter : new ProductFilter();
 }
Exemple #12
0
        public static ProductList Check(int userID, int employeeID, int bussinessID, ProductFilter filter, int?max = 100)
        {
            QueryOutput queryResult;
            var         conditions = new List <string>();

            if (filter != null)
            {
                if (!String.IsNullOrEmpty(filter.Code))
                {
                    conditions.Add(String.Format("and p.Code like N'%{0}%'", filter.Code));
                }
                if (!String.IsNullOrEmpty(filter.Name))
                {
                    conditions.Add(String.Format("and p.Name like N'%{0}%'", filter.Name));
                }
                if (filter.SupplierID.HasValue)
                {
                    conditions.Add(String.Format("and p.SupplierID = {0}", filter.SupplierID.DbValue()));
                }
                if (filter.WarehouseID.HasValue)
                {
                    conditions.Add(String.Format("and w.ID = {0}", filter.WarehouseID.DbValue()));
                }
                if (filter.Returned == "on")
                {
                    conditions.Add(String.Format("and p.Returned > 0"));
                }
            }
            var startImport = "0";

            if (filter != null && filter.From.HasValue)
            {
                startImport = String.Format("isnull((select sum(ip.Quantity) from ImportProduct ip join Import i on ip.ImportID = i.ID and i.Status = 'active' and i.WarehouseID = w.ID and i.SubmitDate < '{0}' where ip.ProductID = p.ID), 0)", filter.From.Value.ToString(Constants.DatabaseDatetimeString));
            }
            var startExport = "0";

            if (filter != null && filter.From.HasValue)
            {
                startExport = String.Format("isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID and e.SubmitDate < '{0}' where ep.Returned = 0 and ep.ProductID = p.ID), 0)", filter.From.Value.ToString(Constants.DatabaseDatetimeString));
            }
            var result = new ProductList("", filter);

            result.Data = Query <ProductInfo>(new DbQuery(userID, employeeID, DbAction.Product.View,
                                                          String.Format(
                                                              @"declare @username nvarchar(50) = (select Username from Login where ID = {3})
                    declare @warehouse table (ID int) insert into @warehouse select WarehouseID from LoginWarehouse where LoginID = {3}
                    declare @products table (ID int, Code nvarchar(50), Name nvarchar(200), Unit nvarchar(50), Price decimal(18, 0), WarehouseName nvarchar(200), TagID int, 
                        TagName nvarchar(100), WarehouseID int, ImportQuantity int, ExportQuantity int, SaleQuantity int, StartImportQuantity int, StartExportQuantity int, Returned int)

                    insert into @products
                    select {4} p.ID, p.Code, p.Name, p.Unit, p.Price, w.Name as [WarehouseName], t.ID as [TagID], t.Name as [TagName], max(i.WarehouseID) as [WarehouseID],
                        isnull((select sum(ip.Quantity) from ImportProduct ip join Import i on ip.ImportID = i.ID and i.Status = 'active' and i.WarehouseID = w.ID {5} {6} where ip.ProductID = p.ID), 0) as [ImportQuantity], 
	                    isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID {7} {8} where ep.Returned = 0 and ep.ProductID = p.ID), 0) as [ExportQuantity],
                        isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID {7} {8} where ep.OrderID is not null and ep.Returned = 0 and ep.ProductID = p.ID), 0) as [SaleQuantity],
                        {9} as [StartImportQuantity], {10} as [StartExportQuantity],
                        isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID {7} {8} where ep.ProductID = p.ID and ep.Returned = 1), 0) as [Returned]
                    from Product p 
                        join ImportProduct ip on p.ID = ip.ProductID
                        join Import i on i.ID = ip.ImportID and i.Status = 'active' 
                        join Warehouse w on w.Status = 'active' and w.ID = i.WarehouseID
                        left join ProductTag pt on p.ID = pt.ProductID
                        left join Tag t on pt.TagID = t.ID and t.Status = 'active'
                    where 
                        p.Status = 'active' and p.BussinessID = {0} 
                        and {2}
                        {1} 
                    group by p.ID, p.Code, p.Name, p.Unit, p.Price, w.Name, t.ID, t.Name, w.ID

                    insert into @products
                    select {4} p.ID, p.Code, p.Name, p.Unit, p.Price, w.Name as [WarehouseName], t.ID as [TagID], t.Name as [TagName], max(i.WarehouseID) as [WarehouseID],
                        isnull((select sum(ip.Quantity) from ImportProduct ip join Import i on ip.ImportID = i.ID and i.Status = 'active' and i.WarehouseID = w.ID {5} {6} where ip.ProductID = p.ID), 0) as [ImportQuantity], 
	                    isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID {7} {8} where ep.Returned = 0 and ep.ProductID = p.ID), 0) as [ExportQuantity],
                        isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID {7} {8} where ep.OrderID is not null and ep.Returned = 0 and ep.ProductID = p.ID), 0) as [SaleQuantity],
                        {9} as [StartImportQuantity], {10} as [StartExportQuantity],
                        isnull((select sum(ep.Quantity) from ExportProduct ep join Export e on ep.ExportID = e.ID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') and e.WarehouseID = w.ID {7} {8} where ep.ProductID = p.ID and ep.Returned = 1), 0) as [Returned]
                    from Product p 
                        left join ImportProduct ip on p.ID = ip.ProductID
                        left join Import i on i.ID = ip.ImportID and i.Status = 'active' 
                        left join Warehouse w on w.Status = 'active' and w.ID = i.WarehouseID
                        left join ProductTag pt on p.ID = pt.ProductID
                        left join Tag t on pt.TagID = t.ID and t.Status = 'active'
                    where 
                        p.Status = 'active' and p.BussinessID = {0} and w.ID is null and p.ID not in (select ID from @products)
                        and {2}
                        {1} 
                    group by p.ID, p.Code, p.Name, p.Unit, p.Price, w.Name, t.ID, t.Name, w.ID
                    select * from @products order by Name",
                                                              bussinessID, String.Join(" ", conditions),
                                                              filter != null && filter.TagID.HasValue ?
                                                              String.Format("t.ID = {0}", filter.TagID.Value) :
                                                              "(t.ID is null or t.ID = (select top 1 TagID from ProductTag where ProductID = p.ID order by TagID desc))",
                                                              userID, max.HasValue ? String.Format("top {0}", max.Value) : "",
                                                              filter != null && filter.From.HasValue ? String.Format("and i.SubmitDate >= '{0}'", filter.From.Value.ToString(Constants.DatabaseDatetimeString)) : "",
                                                              filter != null && filter.To.HasValue ? String.Format("and i.SubmitDate <= '{0}'", filter.To.Value.ToString(Constants.DatabaseDatetimeString)) : "",
                                                              filter != null && filter.From.HasValue ? String.Format("and e.SubmitDate >= '{0}'", filter.From.Value.ToString(Constants.DatabaseDatetimeString)) : "",
                                                              filter != null && filter.To.HasValue ? String.Format("and e.SubmitDate <= '{0}'", filter.To.Value.ToString(Constants.DatabaseDatetimeString)) : "",
                                                              startImport, startExport), true), out queryResult);
            return(result);
        }
Exemple #13
0
        public static ProductList FindAll(int userID, int employeeID, int bussinessID, string message = "", ProductFilter filter = null, bool log = false, int?max = 100)
        {
            QueryOutput queryResult;
            var         conditions = new List <string>();

            if (filter != null)
            {
                if (!String.IsNullOrEmpty(filter.Code))
                {
                    conditions.Add(String.Format("and p.Code = '{0}'", filter.Code));
                }
                if (!String.IsNullOrEmpty(filter.Name))
                {
                    conditions.Add(String.Format("and p.Name like N'%{0}%'", filter.Name));
                }
                if (filter.SupplierID.HasValue)
                {
                    conditions.Add(String.Format("and p.SupplierID = {0}", filter.SupplierID.DbValue()));
                }
                if (filter.WarehouseID.HasValue)
                {
                    conditions.Add(String.Format("and w.ID = {0}", filter.WarehouseID.DbValue()));
                }
                if (filter.TagID.HasValue)
                {
                    conditions.Add(String.Format("and t.ID = {0}", filter.TagID.DbValue()));
                }
                if (filter.Returned == "on")
                {
                    conditions.Add(String.Format("and p.Returned > 0"));
                }
            }
            var result = new ProductList(message, filter);

            result.Data = Query <ProductInfo>(new DbQuery(userID, employeeID, DbAction.Product.View,
                                                          String.Format(
                                                              @"select {3} p.ID, p.Code, p.Name, p.Price, p.Image, p.MadeIn, p.Description, p.OriginalWarranty, p.BussinessWarranty, p.SupplierID, p.Unit, p.Specs, p.Point, p.BussinessID,
                        w.Name as [WarehouseName], t.ID as [TagID], t.Name as [TagName],
                        sum(isnull(ip.Quantity, 0)) - isnull((select sum(ep.Quantity) from ExportProduct ep left join Export e on e.ID = ep.ExportID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') where ep.Returned = 0 and ep.ProductID = p.ID and e.WarehouseID = w.ID), 0) as [Quantity],
                        isnull((select sum(ep.Quantity) from ExportProduct ep left join Export e on e.ID = ep.ExportID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') where ep.ProductID = p.ID and e.WarehouseID = w.ID and ep.Returned = 1), 0) as [Returned]
                    from Product p 
                        left join ProductTag pt on p.ID = pt.ProductID and pt.TagID = (select top 1 TagID from ProductTag where ProductID = p.ID {4} order by TagID desc)
                        left join Tag t on pt.TagID = t.ID and t.Status = 'active'
                        left join ImportProduct ip on p.ID = ip.ProductID
                        left join Import i on i.ID = ip.ImportID and i.Status = 'active' 
                        left join Warehouse w on w.Status = 'active' and w.ID = i.WarehouseID
                    where 
                        p.Status = 'active' and p.BussinessID = {0} 
                        and (w.ID is null or (select Username from Login where ID = {2}) = 'admin' or w.ID in (select WarehouseID from LoginWarehouse where LoginID = {2}))
                        {1} 
                    group by p.ID, p.Code, p.Name, p.Price, p.Image, p.MadeIn, p.Description, p.OriginalWarranty, p.BussinessWarranty, p.SupplierID, p.Unit, p.Specs, p.Point, p.BussinessID, w.Name, t.ID, t.Name, w.ID
                    order by p.Name",
                                                              bussinessID, String.Join(" ", conditions),
                                                              userID, max.HasValue ? String.Format("top {0}", max.Value) : "",
                                                              filter != null && filter.TagID.HasValue ? String.Format("and TagID = {0}", filter.TagID.DbValue()) : ""), log), out queryResult);
            return(result);
        }
Exemple #14
0
        public static List <ProductInfo> FindList(int userID, int employeeID, int bussinessID, ProductFilter filter = null, bool log = false, int?max = 100, string action = null)
        {
            QueryOutput queryResult;

            if (String.IsNullOrEmpty(action))
            {
                action = DbAction.Product.View;
            }
            var conditions = new List <string>();

            if (filter != null)
            {
                if (!String.IsNullOrEmpty(filter.Code))
                {
                    conditions.Add(String.Format("and p.Code like N'%{0}%'", filter.Code));
                }
                if (!String.IsNullOrEmpty(filter.Name))
                {
                    conditions.Add(String.Format("and p.Name like N'%{0}%'", filter.Name));
                }
                if (filter.SupplierID.HasValue)
                {
                    conditions.Add(String.Format("and p.SupplierID = {0}", filter.SupplierID.DbValue()));
                }
                if (filter.TagID.HasValue)
                {
                    conditions.Add(String.Format("and t.ID = {0}", filter.TagID.DbValue()));
                }
                if (filter.Returned == "on")
                {
                    conditions.Add(String.Format("and p.Returned > 0"));
                }
            }
            return(Query <ProductInfo>(new DbQuery(userID, employeeID, action,
                                                   String.Format(
                                                       @"select {2} p.*, t.ID as [TagID], t.Name as [TagName], s.Name as [SupplierName],
                        isnull((select sum(ep.Quantity) from ImportProduct ep left join Import e on e.ID = ep.ImportID and e.Status = 'active' where ep.ProductID = p.ID and e.BussinessID = {0}), 0) - 
                        isnull((select sum(ep.Quantity) from ExportProduct ep left join Export e on e.ID = ep.ExportID and e.Removed = 0 and e.Status in (N'Đã xuất', N'Đã chuyển') where ep.Returned = 0 and ep.ProductID = p.ID and e.BussinessID = {0}), 0) as [Quantity]
                    from Product p
                        left join Supplier s on p.SupplierID = s.ID
                        left join ProductTag pt on p.ID = pt.ProductID and pt.TagID = (select top 1 TagID from ProductTag where ProductID = p.ID {3} order by TagID desc)
                        left join Tag t on pt.TagID = t.ID and t.Status = 'active'
                    where p.Status = 'active' and p.BussinessID = {0} {1} order by Name",
                                                       bussinessID, String.Join(" ", conditions),
                                                       max.HasValue ? String.Format("top {0}", max.Value) : "",
                                                       filter != null && filter.TagID.HasValue ? String.Format("and TagID = {0}", filter.TagID.DbValue()) : ""), log), out queryResult));
        }
Exemple #15
0
        public static ProductList Find(int userID, int employeeID, int bussinessID, string message = "", ProductFilter filter = null, bool log = false, int?max = 100)
        {
            var result = new ProductList(message, filter);

            result.Data = FindList(userID, employeeID, bussinessID, filter, log, max);
            result.Tags = TagInfo.Find(userID, employeeID, bussinessID).Data;
            return(result);
        }