// GET: StockTakes/Create
        public ActionResult Create()
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }


            ViewBag.TenantId             = new SelectList(_tenantServices.GetAllTenants(), "TenantId", "TenantName");
            ViewBag.WarehouseId          = new SelectList(TenantLocationServices.GetAllTenantLocations(CurrentTenantId), "WarehouseId", "WarehouseName");
            ViewBag.CurrentStocktakeId   = -1;
            ViewBag.CurrentStocktakeRef  = "";
            ViewBag.CurrentStocktakeDesc = "";
            ViewBag.CurrentStocktakeDate = "";

            ViewBag.CurrentTenantId = CurrentTenantId;
            ViewBag.CurrentUserId   = CurrentUserId;
            ViewBag.WarehouseId     = CurrentWarehouseId;
            ViewBag.WarehouseName   = CurrentWarehouse.WarehouseName;

            ViewBag.ProductsList = _productServices.GetAllValidProductMasters(CurrentTenantId).Where(x => x.DontMonitorStock != true).Select(p => new StockTakeProductLookupRequest()
            {
                ProductCode        = p.SKUCode,
                ProductName        = p.Name,
                ProductDescription = p.Description
            }).ToList();

            var allProducts = _productServices.GetAllValidProductMasters(CurrentTenantId).ToList();



            var products = new SelectList(allProducts, "ProductId", "NameWithCode").ToList();

            products.Insert(0, new SelectListItem()
            {
                Value = "0", Text = "Select Product"
            });

            ViewBag.Products = new SelectList(products, "Value", "Text");

            // check if any stocktake running
            var model = _stockTakeService.GetStockTakeByStatus(CurrentWarehouseId, 0, CurrentTenantId);

            if (model != null)
            {
                ViewBag.CurrentStocktakeId   = model.StockTakeId;
                ViewBag.CurrentStocktakeRef  = model.StockTakeReference;
                ViewBag.CurrentStocktakeDesc = model.StockTakeDescription;
                ViewBag.CurrentStocktakeDate = model.StartDate;
            }

            var pendingStoppedStockTake = _stockTakeService.GetStockTakeByStatus(CurrentWarehouseId, 1, CurrentTenantId);

            if (pendingStoppedStockTake != null)
            {
                return(RedirectToAction("Details", new { id = pendingStoppedStockTake.StockTakeId }));
            }

            return(View());
        }
        public ActionResult Create([Bind(Include = "TenantConfigId,AlertMinimumProductPrice,EnforceMinimumProductPrice,AlertMinimumPriceMessage,EnforceMinimumPriceMessage,PoReportFooterMsg1,PoReportFooterMsg2,SoReportFooterMsg1,SoReportFooterMsg2,DnReportFooterMsg1,DnReportFooterMsg2,WorksOrderScheduleByMarginHours,WorksOrderScheduleByAmPm,EnableLiveEmails,MiniProfilerEnabled,EnabledRelayEmailServer,EnablePalletingOnPick,WarehouseLogEmailsToDefault,WarehouseScheduleStartTime,WarehouseScheduleEndTime,ErrorLogsForwardEmails,DefaultReplyToAddress,DefaultMailFromText,AutoTransferStockEnabled,EnableStockVarianceAlerts,AuthorisationAdminEmail,DefaultCashAccountID,TenantReceiptPrintHeaderLine1,TenantReceiptPrintHeaderLine2,TenantReceiptPrintHeaderLine3,TenantReceiptPrintHeaderLine4,TenantLogo,PrintLogoForReceipts,SessionTimeoutHours,TenantId,DateCreated,DateUpdated,CreatedBy,UpdatedBy,IsDeleted")] TenantConfig tenantConfig)
        {
            if (ModelState.IsValid)
            {
                if (tenantConfig.TenantConfigId > 0)
                {
                    tenantConfig.TenantId    = CurrentTenantId;
                    tenantConfig.DateUpdated = DateTime.UtcNow;
                    tenantConfig.UpdatedBy   = CurrentUserId;
                    _tenantsServices.UpdateTenantConfig(tenantConfig);
                }
                else
                {
                    tenantConfig.TenantId    = CurrentTenantId;
                    tenantConfig.DateCreated = DateTime.UtcNow;
                    tenantConfig.CreatedBy   = CurrentUserId;
                    _tenantsServices.AddTenantConfig(tenantConfig);
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.DefaultCashAccountID = new SelectList(_accountServices.GetAllValidAccounts(CurrentTenantId).ToList(), "AccountID", "AccountCode", tenantConfig.DefaultCashAccountID);
            ViewBag.TenantId             = new SelectList(_tenantsServices.GetAllTenants(), "TenantId", "TenantName");
            return(View(tenantConfig));
        }