// CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetSupplierListJSON(string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            List <Supplier> suppliers = supplierService.GetSupplierList();

            options.Add(new JSONForCombobox("-1", "All"));

            foreach (var s in suppliers)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = s.supplierCode;
                option.text = s.supplierName;
                options.Add(option);
            }

            if (!String.IsNullOrEmpty(term))
            {
                // used for select2 combobox filtering search result
                options = (from o in options
                           where o.text.ToString().ToLower().Contains(term) || o.id.ToString().ToLower().Contains(term)
                           select o).ToList();
            }

            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetSelectableMonthsJSON(int year, string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            List <int> selectableMonths = reportService.GetSelectableMonths(year);

            options.Add(new JSONForCombobox("-1", "All"));


            foreach (var m in selectableMonths)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = m.ToString();
                option.text = monthsArray[m - 1];
                options.Add(option);
            }

            if (!String.IsNullOrEmpty(term))
            {
                // used for select2 combobox filtering search result
                options = (from o in options
                           where o.text.ToString().ToLower().Contains(term) || o.id.ToString().ToLower() == term
                           select o).ToList();
            }

            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetDepartmentListJSON(string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            List <Department> departments = departmentService.GetAllDepartment();

            options.Add(new JSONForCombobox("-1", "All"));

            foreach (var d in departments)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = d.departmentCode.ToString();
                option.text = d.departmentName;
                options.Add(option);
            }

            if (!String.IsNullOrEmpty(term))
            {
                // used for select2 combobox filtering search result
                options = (from o in options
                           where o.text.ToString().ToLower().Contains(term) || o.id.ToString().ToLower().Contains(term)
                           select o).ToList();
            }

            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetSelectableYearsJSON(string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            int        baseYear = reportService.GetEarliestYear();
            List <int> years    = reportService.GetSelectableYears(baseYear);


            foreach (var y in years)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = y.ToString();
                option.text = y.ToString();
                options.Add(option);
            }

            if (!String.IsNullOrEmpty(term))
            {
                // used for select2 combobox filtering search result
                options = (from o in options
                           where o.text.ToString().ToLower().Contains(term) || o.id.ToString().ToLower().Contains(term)
                           select o).ToList();
            }


            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetStationeryListBasedOnCategoryJSON(string categoryID, string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            List <Stationery> stationeries = stationeryService.GetStationeriesBasedOnCriteria(null, categoryID);

            options.Add(new JSONForCombobox("-1", "All"));

            foreach (var s in stationeries)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = s.itemCode;
                option.text = String.Format("{0} ({1})", s.itemCode, s.description);
                options.Add(option);
            }


            if (!String.IsNullOrEmpty(term))  // used for select2 combobox filtering search result
            {
                string[] searchStringArray = term.Split();
                foreach (string s in searchStringArray)
                {
                    string search = s.ToLower().Trim();
                    if (!String.IsNullOrEmpty(search))
                    {
                        options = options.Where(x => (x.text.ToLower().Contains(search) || x.id.ToLower().Contains(search))).ToList();
                    }
                }
            }

            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // METHODS FOR SELECT2 COMBOBOX
        // CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetCategoryListJSON(string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            List <Category> categories = stationeryService.GetAllCategory();

            options.Add(new JSONForCombobox("-1", "All"));

            foreach (var c in categories)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = c.categoryID.ToString();
                option.text = c.categoryName;
                options.Add(option);
            }

            if (!String.IsNullOrEmpty(term))
            {
                // used for select2 combobox filtering search result
                options = (from o in options
                           where o.text.ToString().ToLower().Contains(term) || o.id.ToString().ToLower().Contains(term)
                           select o).ToList();
            }

            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // CK - Store Clerk | Store Supervisor | Store Manager
        public ActionResult GetStationeryListJSON(string term = null)
        {
            List <JSONForCombobox> options = new List <JSONForCombobox>();

            List <Stationery> stationeries = stationeryService.GetStationeriesBasedOnCriteria(term);

            foreach (var s in stationeries)
            {
                JSONForCombobox option = new JSONForCombobox();
                option.id   = s.itemCode;
                option.text = String.Format("{0} ({1})", s.itemCode, s.description);
                options.Add(option);
            }
            return(Json(options, JsonRequestBehavior.AllowGet));
        }
        // CK - Store Clerk | Store Supervisor | Store Manager
        public JsonResult GetMonthListJSON(string term = null)
        {
            List <int> years = reportService.GetSelectableYears(reportService.GetEarliestYear());

            years.Reverse();

            List <JSONForCombobox> options = new List <JSONForCombobox>();

            foreach (int y in years)
            {
                List <int> selectableMonth = reportService.GetSelectableMonths(y);
                foreach (int m in selectableMonth)
                {
                    JSONForCombobox option = new JSONForCombobox();
                    option.id   = String.Format("{0}-{1}", m, y);                  // eg: 1-2017, 2-2017
                    option.text = String.Format("{0} {1}", monthsArray[m - 1], y); // eg: Jan 2017, Feb 2017
                    options.Add(option);
                }
            }


            if (!String.IsNullOrEmpty(term))
            {
                // used for select2 combobox filtering search result
                string[] searchStringArray = term.Split();
                foreach (string s in searchStringArray)
                {
                    string search = s.ToLower().Trim();
                    if (!String.IsNullOrEmpty(search))
                    {
                        options = (from o in options
                                   where o.text.ToString().ToLower().Contains(search) || o.id.ToString().ToLower().Contains(search)
                                   select o).ToList();
                    }
                }
            }

            return(Json(options, JsonRequestBehavior.AllowGet));
        }