Esempio n. 1
0
        public int GetDetailTaxForStore(string StoreId)
        {
            NuWebNCloud.Shared.Factory.Settings.TaxFactory _factory = new Settings.TaxFactory();
            var datas = _factory.GetListTax(StoreId);

            if (datas != null && datas.Any())
            {
                var tax = datas.Where(tb => tb.IsActive == true)
                          .Select(ss => ss.TaxType).FirstOrDefault();
                return(tax);
            }
            return(0);
        }
Esempio n. 2
0
        public List <StoreModels> GetListStoresInfo(List <string> lstOrgId = null)
        {
            //using (var db = new NuWebContext())
            //{
            //    var listItemInRecipe = (from ri in db.I_Recipe_Item
            //                            join i in db.I_Ingredient on ri.IngredientId equals i.Id
            //                            where ri.Status != (int)Commons.EStatus.Deleted
            //                            && i.IsCheckStock
            //                            group ri by ri.ItemId into g
            //                            where g.Count() == 1
            //                            select new { g.Key }
            //                            ).ToList();

            //}

            List <StoreModels> listStores = new List <StoreModels>();
            List <StoreModels> listItems  = new List <StoreModels>();

            try
            {
                if (System.Web.HttpContext.Current.Session["ListStoresInfo"] != null)
                {
                    listStores = (List <StoreModels>)System.Web.HttpContext.Current.Session["ListStoresInfo"];
                }
                else
                {
                    var currentUser = (UserSession)System.Web.HttpContext.Current.Session["User"];
                    if (currentUser != null)
                    {
                        var listOrganizationId = lstOrgId;
                        if (listOrganizationId == null)
                        {
                            listOrganizationId = currentUser.ListOrganizationId.ToList();
                        }

                        if (listOrganizationId != null && listOrganizationId.Any())
                        {
                            // Tax info
                            NuWebNCloud.Shared.Factory.Settings.TaxFactory taxFactory = new Settings.TaxFactory();
                            List <Models.Settings.TaxModels> lstTax = new List <Models.Settings.TaxModels>();

                            //=== Get list companies info ===//
                            ////=== Merchant not extend
                            // Get list stores info of listOrganizationId
                            GetStoreWeb2Request paraBody = new GetStoreWeb2Request();
                            paraBody.ListOrgID = listOrganizationId;
                            var                result     = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.Store_Get_Web2, null, paraBody);
                            dynamic            data       = result.Data;
                            var                lstC       = data["ListStore"];
                            var                lstContent = JsonConvert.SerializeObject(lstC);
                            List <StoreModels> lstStores  = JsonConvert.DeserializeObject <List <StoreModels> >(lstContent);

                            string hostUrlExtend = null;
                            if (!currentUser.IsMerchantExtend)
                            {
                                var stall14 = lstStores.Where(ww => ww.StoreCode == Commons.Stall14StoreCode).FirstOrDefault();
                                // Add value common for FJ Daily Sales report
                                if (stall14 != null)
                                {
                                    Commons.Stall14StoreId   = stall14.Id;
                                    Commons.Stall14StoreName = stall14.Name;
                                }

                                // Get list tax info
                                lstTax = taxFactory.GetListTax(null, null, listOrganizationId);
                            }
                            else
                            {
                                hostUrlExtend = currentUser.HostApi;
                                ////=== Merchant extend
                                // Get list stores info of ListStoreIds
                                if (currentUser.ListMerchantExtends != null && currentUser.ListMerchantExtends.Any())
                                {
                                    foreach (var item in currentUser.ListMerchantExtends)
                                    {
                                        var paraBodyExtend = new GetStoreWeb2Request();
                                        paraBodyExtend.ListStoreID = item.ListStoreIds;
                                        var                resultExtend     = (ResponseApiModels)ApiResponse.PostWithoutHostConfig <ResponseApiModels>(item.HostApiURL + "/" + Commons.Store_Get_Web2, null, paraBodyExtend);
                                        dynamic            dataExtend       = resultExtend.Data;
                                        var                lstExtend        = dataExtend["ListStore"];
                                        var                lstContentExtend = JsonConvert.SerializeObject(lstExtend);
                                        List <StoreModels> lstStoresExtend  = JsonConvert.DeserializeObject <List <StoreModels> >(lstContentExtend);

                                        if (lstStoresExtend != null && lstStoresExtend.Any())
                                        {
                                            foreach (var store in lstStoresExtend)
                                            {
                                                listStores.Add(new StoreModels()
                                                {
                                                    Id               = store.Id,
                                                    Name             = store.Name,
                                                    CompanyId        = store.CompanyId,
                                                    CompanyName      = store.CompanyName,
                                                    HostUrlExtend    = item.HostApiURL,
                                                    IsIncludeTax     = store.IsIncludeTax,
                                                    OrganizationId   = store.OrganizationId,
                                                    OrganizationName = store.OrganizationName,
                                                    NameExtend       = string.Format("{0} in {1}", store.Name, store.OrganizationName),
                                                });
                                            }
                                        }
                                    }
                                }
                            }

                            lstStores = lstStores.Where(x => currentUser.ListStoreID.Contains(x.Id)).ToList();

                            string nameExtend   = "";
                            bool   isIncludeTax = true;
                            foreach (var store in lstStores)
                            {
                                if (!currentUser.IsMerchantExtend)
                                {
                                    int taxType = lstTax.Where(an => an.StoreID == store.Id && an.IsActive).OrderBy(oo => oo.Name).Select(ss => ss.TaxType).FirstOrDefault();
                                    isIncludeTax = (taxType == (int)Commons.ETax.AddOn) ? false : true;
                                }
                                else
                                {
                                    isIncludeTax = store.IsIncludeTax;
                                    nameExtend   = string.Format("{0} in {1}", store.Name, store.OrganizationName);
                                }
                                listStores.Add(new StoreModels()
                                {
                                    Id               = store.Id,
                                    Name             = store.Name,
                                    CompanyId        = store.CompanyId,
                                    CompanyName      = store.CompanyName,
                                    HostUrlExtend    = hostUrlExtend,
                                    IsIncludeTax     = isIncludeTax,
                                    OrganizationId   = store.OrganizationId,
                                    OrganizationName = store.OrganizationName,
                                    NameExtend       = nameExtend,
                                });
                            }

                            if (listStores != null && listStores.Any())
                            {
                                listStores = listStores.OrderBy(o => o.CompanyName).ThenBy(oo => oo.Name).ToList();

                                System.Web.HttpContext.Current.Session.Add("ListStoresInfo", listStores);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error("GetListStoresInfo: " + e);
            }
            return(listStores);
        }