//// POST //[AllowAnonymous] //[Route("create_category")] //[HttpPost] //public async Task<BudgetCategory> CreateNewCategory(BudgetCategory newCat) //{ // try // { // //Check if it allready exists // var result = await i.GetCategoryByNameAsync(newCat.Name); // bool exists = false; // foreach(var item in result) // { // if(item.Name == newCat.Name) // { // exists = true; // break; // } // } // if (exists == false) // { // var id = User.Identity.GetUserId<int>(); // var user = await i.SelectUserAsync(id); // newCat.HouseholdId = user.Household; // newCat.Id = await i.InsertCategoryAsync(newCat); // return newCat; // } // return null;//Did not need to creat it because it exists // } // catch (Exception e) // { // throw new HttpResponseException(HttpStatusCode.BadRequest); // } //} // POST // POST public async Task <BudgetCategory> CreateNewCategory(BudgetCategory newCat) { var id = User.Identity.GetUserId <int>(); var user = await i.SelectUserAsync(id); //Check if it allready exists var result = await i.GetCategoryByNameAndHouseholdAsync(newCat.Name, user.Household); bool exists = false; foreach (var item in result) { if (item.Name == newCat.Name) { newCat = item; exists = true; break; } } if (exists == false) { newCat.HouseholdId = user.Household; newCat.Id = await i.InsertCategoryAsync(newCat); return(newCat); } return(newCat); }
public ActionResult SaveCategory(Models.BudgetCategory bc) { ProjectDonor pd = projectService.GetProjectDonorById(bc.EntityBudgetCategory.ProjectDonorId.Value); BudgetCategory budgetCategory = budgetService.GetBudgetCategoryByNumber(bc.Number, pd.Id); if (bc.BudgetCategoryId == null || bc.BudgetCategoryId.Trim() == "") { if (budgetCategory == null) { budgetService.CreateBudgetCategory(bc.EntityBudgetCategory, pd); } else { ViewBag.ActionStatus = 0; ViewBag.StatusMsg = string.Format(Resources.BudgetController_String_CategoryExists, bc.EntityBudgetCategory.Number); } } else { if (budgetCategory == null) { budgetService.UpdateBudgetCategory(bc.EntityBudgetCategory); } else if (budgetCategory != null && budgetCategory.Id == bc.EntityBudgetCategory.Id) { budgetService.UpdateBudgetCategory(bc.EntityBudgetCategory); } else { ViewBag.ActionStatus = 0; ViewBag.StatusMsg = string.Format(Resources.BudgetController_String_CategoryExists, bc.EntityBudgetCategory.Number); } } return(CategoryList(pd.Id)); }
private async Task AddNewItem() { var newItem = new BudgetCategory(); BudgetCategories.Add(newItem); await _dataStore.AddBudgetCategoryAsync(newItem); }
public async Task UpdateCategoryAsync_editsCategory_then_saves_when_EffectiveFrom_unchanged_or_earlier(string originalDateString, string editedDateString) { // Arrange var testID = 1; var originalCategory = new BudgetCategory { ID = testID, Name = "Test", Amount = 0, Type = BudgetType.Expense, EffectiveFrom = DateTime.Parse(originalDateString) }; var editedCategory = new BudgetCategory { ID = testID, EffectiveFrom = DateTime.Parse(editedDateString) }; var categories = new List <BudgetCategory> { originalCategory }.AsQueryable(); var sequence = new MockSequence(); _mockRepo.Setup(m => m.GetCategories()).Returns(categories); _mockRepo.Setup(m => m.GetTransactions(It.IsAny <bool>(), It.IsAny <bool>())).Returns(new List <Transaction>().AsQueryable()); _mockRepo.Setup(m => m.DeleteBudgetCategory(It.IsAny <BudgetCategory>())); _mockRepo.InSequence(sequence).Setup(m => m.EditBudgetCategory(It.IsAny <BudgetCategory>())); _mockRepo.InSequence(sequence).Setup(m => m.SaveChangesAsync()).ReturnsAsync(1); // Act var result = await _testService.UpdateCategoryAsync(testID, 0, editedCategory.EffectiveFrom, BudgetType.Expense); // Assert _mockRepo.Verify(m => m.EditBudgetCategory(It.Is <BudgetCategory>(c => c.ID == testID)), Times.Once()); _mockRepo.Verify(m => m.SaveChangesAsync(), Times.Once()); }
private bool ValidateModel(BudgetCategory model) { var context = new ValidationContext(model, null, null); var results = new List <ValidationResult>(); return(Validator.TryValidateObject(model, context, results, true)); }
public bool CreateCategory(CategoryCreate model) { var entity = new Category() { UserId = _userId, Name = model.Name, ListOfBudgetIds = model.ListOfBudgetIds }; var amount = model.CategoryAmount; using (var ctx = new ApplicationDbContext()) { foreach (int i in entity.ListOfBudgetIds) { var budgetCategoryEntity = new BudgetCategory() { BudgetId = i, CategoryId = entity.CategoryId }; ctx.BudgetCategory.Add(budgetCategoryEntity); } ctx.Categories.Add(entity); //ctx.BudgetCategory.Add(amount); return(ctx.SaveChanges() == 1); } }
public List <ProjectBudget> GetBudgetLinesNotInBudget(ProjectDonor pd, BudgetCategory bc) { try { List <ProjectBudget> budgetLineList = new List <ProjectBudget>(); using (var context = new SCMSEntities()) { var budgetLines = context.ProjectBudgets.Where(b => b.BudgetCategory.ProjectDonorId == pd.Id).ToList <ProjectBudget>(); var subLines = context.ProjectBudgets.Where(s => s.BudgetCategoryId == bc.Id).ToList <ProjectBudget>(); foreach (var subLine in subLines) { if (!SubLineExistsInBudgetLines(subLine, budgetLines)) { budgetLineList.Add(subLine); } } } //sort bl budgetLineList = SCMS.Utils.BudgetLineSorter.SortBudgetLine(budgetLineList); return(budgetLineList); } catch (Exception ex) { return(new List <ProjectBudget>()); } }
public async Task <BudgetCategory> AddBudgetCategoryAsync(BudgetCategory category) { var inserted = await connection.InsertAsync(category); //category.IsNew = false; return(category); }
public List <ProjectBudget> GetProjectBLByCategory(ProjectDonor pd, BudgetCategory bc) { try { List <ProjectBudget> projectBL = new List <ProjectBudget>(); using (var context = new SCMSEntities()) { var budgetLines = context.ProjectBudgets.Where(b => b.BudgetCategory.ProjectDonorId == pd.Id).ToList <ProjectBudget>(); var subLines = context.ProjectBudgets.Where(s => s.BudgetCategoryId == bc.Id).ToList <ProjectBudget>(); foreach (var budgetLine in budgetLines) { var curr = budgetLine.BudgetCategory.ProjectDonor.Currency; if (BudgetLineExistsInCategory(budgetLine, subLines)) { projectBL.Add(budgetLine); } } } projectBL = SCMS.Utils.BudgetLineSorter.SortBudgetLine(projectBL); return(projectBL); } catch (Exception ex) { return(new List <ProjectBudget>()); } }
async Task <BudgetCategory> GetBudgetCategoryAsync(int categoryId) { BudgetCategory _category = null; using (UnitOfWork uow = new UnitOfWork(this.dbFilePath)) { var _resultsCategory = await uow.GetBudgetCategoryAsync(categoryId); if (_resultsCategory.Successful) { _category = _resultsCategory.Category; } else { if (_resultsCategory.WorkException != null) { WriteErrorCondition(_resultsCategory.WorkException); } else if (!string.IsNullOrEmpty(_resultsCategory.Message)) { WriteErrorCondition(_resultsCategory.Message); } else { WriteErrorCondition("An unknown error has occurred loading item's BudgetCategory object"); } } } return(_category); }
public bool UpdateTransaction(TransactionEdit model) { using (var ctx = new ApplicationDbContext()) { var budgetCategoryList = ctx. BudgetCategory .Where(e => e.CategoryId == model.CategoryId) .ToList(); if (budgetCategoryList == null) { var newBudgetCategory = new BudgetCategory { BudgetId = model.BudgetId, CategoryId = model.CategoryId }; } var entity = ctx .Transactions .Single(e => e.TransactionId == model.TransactionId && e.UserId == _userId); entity.TransactionId = model.TransactionId; entity.BudgetId = model.BudgetId; entity.MerchantName = model.MerchantName; entity.Amount = model.Amount; entity.TransactionDate = model.TransactionDate; entity.CategoryId = model.CategoryId; return(ctx.SaveChanges() == 1); } }
public ActionResult DeleteCategory(string id) { BudgetCategory bc = budgetService.GetBudgetCategoryById(id); budgetService.DeleteBudgetCategory(id); return(CategoryList(bc.ProjectDonorId.Value)); }
public async Task UpdateCategoryAsync_addsCategory_then_saves_when_EffectiveFrom_moved_later() { // Arrange var testID = 1; var originalCategory = new BudgetCategory { ID = testID, Name = "Test", Amount = 0, Type = BudgetType.Expense, EffectiveFrom = DateTime.Parse("1/1/2017") }; var editedCategory = new BudgetCategory { ID = testID, EffectiveFrom = originalCategory.EffectiveFrom.AddDays(5) }; var categories = new List <BudgetCategory> { originalCategory }.AsQueryable(); var sequence = new MockSequence(); _mockRepo.Setup(m => m.GetCategories()).Returns(categories); _mockRepo.Setup(m => m.GetTransactions(It.IsAny <bool>(), It.IsAny <bool>())).Returns(new List <Transaction>().AsQueryable()); _mockRepo.Setup(m => m.EditPayee(It.IsAny <Payee>())); _mockRepo.Setup(m => m.EditTransaction(It.IsAny <Transaction>())); _mockRepo.InSequence(sequence).Setup(m => m.AddBudgetCategory(It.IsAny <BudgetCategory>())); _mockRepo.InSequence(sequence).Setup(m => m.SaveChangesAsync()).ReturnsAsync(1); // Act var result = await _testService.UpdateCategoryAsync(testID, 0, editedCategory.EffectiveFrom, BudgetType.Expense); // Assert _mockRepo.Verify(m => m.AddBudgetCategory(It.IsAny <BudgetCategory>()), Times.Once()); _mockRepo.Verify(m => m.SaveChangesAsync(), Times.Once()); }
public ActionResult WizardSubmit(BankAccount bankAccount, BudgetCategory budgetCategory, BudgetItem budgetCategoryItem, int houseId, HouseholdViewModel model) { var user = db.Users.Find(User.Identity.GetUserId()); if (ModelState.IsValid) { bankAccount.HouseholdId = houseId; bankAccount.OwnerId = user.Id; bankAccount.Created = DateTime.Now; db.BankAccounts.Add(bankAccount); db.SaveChanges(); var household = db.Households.Find(houseId); budgetCategory.Household = household; budgetCategory.Created = DateTime.Now; db.BudgetCategories.Add(budgetCategory); db.SaveChanges(); budgetCategoryItem.BudgetCategoryId = budgetCategory.Id; budgetCategoryItem.Created = DateTime.Now; db.BudgetItems.Add(budgetCategoryItem); db.SaveChanges(); model.Household.IsConfigured = true; db.SaveChanges(); } return(RedirectToAction("Dashboard", new { user.Household.Id })); }
public async Task <IActionResult> PutBudgetCategory([FromRoute] int id, [FromBody] BudgetCategory budgetCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != budgetCategory.Id) { return(BadRequest()); } _context.Entry(budgetCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BudgetCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CreateValidBudgetCategory() => _model = new BudgetCategory { ID = 1, Name = "Valid category name", Amount = 200, Type = BudgetType.Income, EffectiveFrom = new DateTime(2017, 12, 12) };
public ActionResult <string> EditBudgetCategory([FromBody] string value) { string result = "empty"; BudgetCategory category = new BudgetCategory(); result = budgetDAL.EditBudgetCategory(category); return(result); }
public ActionResult DeleteConfirmed(int id) { BudgetCategory budgetCategory = db.BudgetCategories.Find(id); db.BudgetCategories.Remove(budgetCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public JsonResult DeleteCategory(BudgetCategory budgetcategory) { var deletedbc = db.BudgetCategories.Find(budgetcategory.BudgetID, budgetcategory.CategoryID); db.BudgetCategories.Remove(deletedbc); db.SaveChanges(); return(Json(budgetcategory)); }
public JsonResult AddCategory(BudgetCategory budgetcategory) { db.BudgetCategories.Add(budgetcategory); db.SaveChanges(); var categoryName = db.Categories.Find(budgetcategory.CategoryID).CategoryName; return(Json(categoryName)); }
// GET: BudgetCategories/Create public ActionResult Create(int id) { var budgetCategory = new BudgetCategory { HouseholdId = id }; return(View(budgetCategory)); }
public async Task UpdateCategoryAsync_reassigns_transactions_correctly_when_EffectiveFrom_moved_earlier(string newDateString, int expectedReassignments) { // Arrange var reassignedTransactions = new List <Transaction>(); var transactions = new List <Transaction> { new Transaction { ID = 2, OverrideCategoryID = 2, Date = DateTime.Parse("12/15/2016") }, new Transaction { ID = 1, OverrideCategoryID = 3, Date = DateTime.Parse("11/25/2016") }, new Transaction { ID = 3, OverrideCategoryID = 2, Date = DateTime.Parse("12/25/2016") } }.AsQueryable(); var category = new BudgetCategory { ID = 1, Name = "test", EffectiveFrom = DateTime.Parse(newDateString) }; var categories = new List <BudgetCategory> { new BudgetCategory { ID = 1, Name = "test", EffectiveFrom = DateTime.Parse("1/1/2017") }, new BudgetCategory { ID = 2, Name = "test", EffectiveFrom = DateTime.Parse("12/1/2016") }, new BudgetCategory { ID = 3, Name = "test", EffectiveFrom = DateTime.Parse("11/1/2016") } }.AsQueryable(); _mockRepo.Setup(m => m.GetCategories()).Returns(categories); _mockRepo.Setup(m => m.GetTransactions(It.IsAny <bool>(), It.IsAny <bool>())).Returns(transactions); _mockRepo.Setup(m => m.EditTransaction(It.IsAny <Transaction>())).Callback <Transaction>(t => reassignedTransactions.Add(t)); // Act var result = await _testService.UpdateCategoryAsync(1, 0, category.EffectiveFrom, BudgetType.Expense); // Assert Assert.AreEqual(expectedReassignments, reassignedTransactions.Count, "Incorrect number of transactions reassigned"); foreach (var reassignment in reassignedTransactions) { Assert.AreEqual(1, reassignment.OverrideCategoryID, "BudgetCategoryID was not changed"); } }
public BudgetCategory RandomBudgetCategory(Budget budget, eBudgetCategoryType budgetCategoryType) { var icon = new BudgetCategoryIcon(new BudgetCategoryIconId(), RandomString(4)); return(BudgetCategory.Create(budget, RandomString(4), icon, budgetCategoryType)); }
private void ReassingTransactionsByDate(BudgetCategory fromCategory, BudgetCategory toCategory) { foreach (Transaction tran in _context.GetTransactions() .Where(t => t.OverrideCategoryID == fromCategory.ID && t.Date >= toCategory.EffectiveFrom)) { tran.OverrideCategoryID = toCategory.ID; _context.EditTransaction(tran); } }
public async Task DeleteBudgetCategoryAsync(BudgetCategory category) { if (context.BudgetCategory.Any(c => c.id == category.id)) { await Task.Run(() => context.BudgetCategory.Attach(category)); await Task.Run(() => context.Entry(category).State = Microsoft.EntityFrameworkCore.EntityState.Deleted); } }
async Task LoadIncomeItemsAsync(int categoryId) { using (UnitOfWork uow = new UnitOfWork(this.dbFilePath)) { var _resultsCategory = await uow.GetBudgetCategoryAsync(categoryId); if (_resultsCategory.Successful) { BudgetCategory category = _resultsCategory.Results; var _resultsIncomeItems = await uow.GetCategoryIncomeItemsAsync(category); if (_resultsIncomeItems.Successful) { foreach (var item in _resultsIncomeItems.Results) { item.budgetCategory = category; item.ItemType = BudgetItemType.Income; this.BudgetItems.Add(item); var vm = new BudgetItemViewModel(this.dbFilePath); await vm.PopulateVMAsync(item); this.BudgetItemVMs.Add(vm); } } else { if (_resultsIncomeItems.WorkException != null) { WriteErrorCondition(_resultsIncomeItems.WorkException); } else if (!string.IsNullOrEmpty(_resultsIncomeItems.Message)) { WriteErrorCondition(_resultsIncomeItems.Message); } else { WriteErrorCondition("An unknown error has occurred"); } } } else { if (_resultsCategory.WorkException != null) { WriteErrorCondition(_resultsCategory.WorkException); } else if (!string.IsNullOrEmpty(_resultsCategory.Message)) { WriteErrorCondition(_resultsCategory.Message); } else { WriteErrorCondition("An unknown error has occurred"); } } } }
public ActionResult Edit([Bind(Include = "Id,Name,IsParent,IsPositive")] BudgetCategory budgetCategory) { if (ModelState.IsValid) { db.Entry(budgetCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(budgetCategory)); }
public static string[] Fillcategories() { List <string> _categories = new List <string>(); _categories.Add("All Expenses ex. Miscellaneous"); _categories.Add("All Income ex. Miscellaneous"); _categories.Add("Gross Salary"); _categories.AddRange(BudgetCategory.GetCategories(true)); return(_categories.ToArray()); }
public async Task AddCategory(CategoryViewModel viewModel) { var category = new BudgetCategory { Name = viewModel.Category }; DbContext.BudgetCategories.Add(category); await DbContext.SaveChangesAsync(); }
public ActionResult Edit([Bind(Include = "Id,HouseholdId,Name,Description,TargetAmount")] BudgetCategory budgetCategory) { if (ModelState.IsValid) { db.Entry(budgetCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HouseholdId = new SelectList(db.Households, "Id", "Name", budgetCategory.HouseholdId); return(View(budgetCategory)); }
public static string GetSqlCategoryString(BudgetCategory cat) { if (cat == BudgetCategory.MDA) return "(Varegruppe >= 100 AND Varegruppe < 200) "; if (cat == BudgetCategory.AudioVideo) return "(Varegruppe >= 200 AND Varegruppe < 300) "; if (cat == BudgetCategory.SDA) return "(Varegruppe >= 300 AND Varegruppe < 400) "; if (cat == BudgetCategory.Tele) return "(Varegruppe >= 400 AND Varegruppe < 500) "; if (cat == BudgetCategory.Data) return "(Varegruppe >= 500 AND Varegruppe < 600) "; if (cat == BudgetCategory.Cross) return "(Varegruppe >= 200 AND Varegruppe < 300) OR (Varegruppe >= 400 AND Varegruppe < 500) OR (Varegruppe >= 500 AND Varegruppe < 600) "; if (cat == BudgetCategory.MDASDA) return "(Varegruppe >= 100 AND Varegruppe < 200) OR (Varegruppe >= 300 AND Varegruppe < 0) "; if (cat == BudgetCategory.Butikk) return "(Varegruppe >= 100) "; return "(Varegruppe > 0) "; }
public BudgetInfo GetBudgetInfo(DateTime date, BudgetCategory cat) { return GetBudgetInternal(date, 0, cat); }
private void UpdateBudget(BudgetCategory cat = BudgetCategory.None) { if (cat != BudgetCategory.None) ClearBudgetHash(cat); if (cat != BudgetCategory.None) RunBudget(cat); else { BudgetCategory page = currentBudgetPage(); if (page != BudgetCategory.None) ClearBudgetHash(page); if (page != BudgetCategory.None) RunBudget(page); else if (!appConfig.savedBudgetPage.Equals(BudgetCategoryClass.TypeToName(BudgetCategory.None))) RunBudget(BudgetCategoryClass.NameToType(appConfig.savedBudgetPage)); else RunBudget(BudgetCategory.Daglig); } }
private void ClearBudgetHash(BudgetCategory cat, bool bg = false) { if (cat != BudgetCategory.None) { if (cat == BudgetCategory.MDA) appConfig.strBudgetMda = ""; else if (cat == BudgetCategory.AudioVideo) appConfig.strBudgetAv = ""; else if (cat == BudgetCategory.SDA) appConfig.strBudgetSda = ""; else if (cat == BudgetCategory.Tele) appConfig.strBudgetTele = ""; else if (cat == BudgetCategory.Data) appConfig.strBudgetData = ""; else if (cat == BudgetCategory.Cross) appConfig.strBudgetCross = ""; else if (cat == BudgetCategory.Kasse) appConfig.strBudgetKasse = ""; else if (cat == BudgetCategory.Aftersales) appConfig.strBudgetAftersales = ""; else if (cat == BudgetCategory.MDASDA) appConfig.strBudgetMdasda = ""; else if (cat == BudgetCategory.Daglig) appConfig.strBudgetDaily = ""; else if (cat == BudgetCategory.AlleSelgere) appConfig.strBudgetAllSales = ""; } else { appConfig.strBudgetMda = ""; appConfig.strBudgetAv = ""; appConfig.strBudgetSda = ""; appConfig.strBudgetTele = ""; appConfig.strBudgetData = ""; appConfig.strBudgetCross = ""; appConfig.strBudgetKasse = ""; appConfig.strBudgetAftersales = ""; appConfig.strBudgetMdasda = ""; appConfig.strBudgetDaily = ""; appConfig.strBudgetAllSales = ""; } SaveSettings(); if (!bg && !EmptyDatabase()) { buttonBudgetUpdate.BackColor = Color.LightGreen; buttonBudgetUpdate.ForeColor = SystemColors.ControlText; } }
public void HighlightBudgetButton(BudgetCategory cat) { try { buttonBudgetMda.Enabled = appConfig.budgetShowMda; buttonBudgetAv.Enabled = appConfig.budgetShowAudioVideo; buttonBudgetSda.Enabled = appConfig.budgetShowSda; buttonBudgetTele.Enabled = appConfig.budgetShowTele; buttonBudgetData.Enabled = appConfig.budgetShowData; buttonBudgetCross.Enabled = appConfig.budgetShowCross; buttonBudgetKasse.Enabled = appConfig.budgetShowKasse; buttonBudgetAftersales.Enabled = appConfig.budgetShowAftersales; buttonBudgetMdaSda.Enabled = appConfig.budgetShowMdasda; buttonBudgetButikk.Enabled = appConfig.budgetShowButikk; buttonBudgetDaily.BackColor = SystemColors.ControlLight; buttonBudgetMda.BackColor = SystemColors.ControlLight; buttonBudgetAv.BackColor = SystemColors.ControlLight; buttonBudgetSda.BackColor = SystemColors.ControlLight; buttonBudgetTele.BackColor = SystemColors.ControlLight; buttonBudgetData.BackColor = SystemColors.ControlLight; buttonBudgetCross.BackColor = SystemColors.ControlLight; buttonBudgetKasse.BackColor = SystemColors.ControlLight; buttonBudgetAftersales.BackColor = SystemColors.ControlLight; buttonBudgetMdaSda.BackColor = SystemColors.ControlLight; buttonBudgetButikk.BackColor = SystemColors.ControlLight; if (cat == BudgetCategory.MDA) buttonBudgetMda.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.AudioVideo) buttonBudgetAv.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.SDA) buttonBudgetSda.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Tele) buttonBudgetTele.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Data) buttonBudgetData.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Cross) buttonBudgetCross.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Kasse) buttonBudgetKasse.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Aftersales) buttonBudgetAftersales.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.MDASDA) buttonBudgetMdaSda.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Butikk) buttonBudgetButikk.BackColor = Color.LightSkyBlue; else if (cat == BudgetCategory.Daglig) buttonBudgetDaily.BackColor = Color.LightSkyBlue; this.Update(); } catch (Exception ex) { Log.Unhandled(ex); } }
private DataTable MakeTableBudget(BudgetCategory cat) { try { DataTable dtWork = ReadyTableOverall(); var rowsGet = main.database.CallMonthTable(dtTil, main.appConfig.Avdeling).Select(BudgetCategoryClass.GetSqlCategoryString(cat) + " AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')"); sqlce = rowsGet.Any() ? rowsGet.CopyToDataTable() : sqlce.Clone(); DateTime dtMainFra = dtFra; DateTime dtMainTil = dtTil; object g; decimal Omset_totaltSelgere = 0, OmsetExMva_totaltSelgere = 0, Inntjen_totaltSelgere = 0; budgetInfo.chartdata_inntjen = new List<BudgetChartData>() { }; budgetInfo.chartdata_omset = new List<BudgetChartData>() { }; budgetInfo.chartdata_kvalitet = new List<BudgetChartData>() { }; budgetInfo.chartdata_effektivitet = new List<BudgetChartData>() { }; budgetInfo.comparelist = new List<BudgetCompareData>() { }; if (cat == BudgetCategory.MDA || cat == BudgetCategory.AudioVideo || cat == BudgetCategory.SDA || cat == BudgetCategory.Tele || cat == BudgetCategory.Data || cat == BudgetCategory.Cross || cat == BudgetCategory.MDASDA) { // Egen avdeling if (sqlce.Rows.Count > 0) { decimal omset_totaltAvdeling = 0, omsetExMva_totaltAvdeling = 0, inntjen_totaltAvdeling = 0, margin_totaltAvdeling = 0; g = sqlce.Compute("Sum(Salgspris)", ""); if (!DBNull.Value.Equals(g)) omset_totaltAvdeling = Convert.ToDecimal(g); g = sqlce.Compute("Sum(SalgsprisExMva)", ""); if (!DBNull.Value.Equals(g)) omsetExMva_totaltAvdeling = Convert.ToDecimal(g); g = sqlce.Compute("Sum(Btokr)", ""); if (!DBNull.Value.Equals(g)) inntjen_totaltAvdeling = Convert.ToDecimal(g); if (omset_totaltAvdeling != 0) margin_totaltAvdeling = inntjen_totaltAvdeling / omsetExMva_totaltAvdeling; else margin_totaltAvdeling = 0; budgetInfo.comparelist.Add(new BudgetCompareData("own", "Din avdeling", omset_totaltAvdeling, inntjen_totaltAvdeling, margin_totaltAvdeling)); } // Egen avdeling, sist år var rowLastYear = main.database.CallMonthTable(dtTil.AddYears(-1), main.appConfig.Avdeling).Select(BudgetCategoryClass.GetSqlCategoryString(cat) + " AND (Dato >= '" + dtFra.AddYears(-1).ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.AddYears(-1).ToString("yyy-MM-dd") + "')"); DataTable dtLastYear = rowLastYear.Any() ? rowLastYear.CopyToDataTable() : sqlce.Clone(); if (dtLastYear.Rows.Count > 0) { decimal compare_omset = 0, compare_inntjen = 0, compare_margin = 0, compare_omsetexmva = 0; g = dtLastYear.Compute("Sum(Salgspris)", ""); if (!DBNull.Value.Equals(g)) compare_omset = Convert.ToDecimal(g); g = dtLastYear.Compute("Sum(SalgsprisExMva)", ""); if (!DBNull.Value.Equals(g)) compare_omsetexmva = Convert.ToDecimal(g); g = dtLastYear.Compute("Sum(Btokr)", ""); if (!DBNull.Value.Equals(g)) compare_inntjen = Convert.ToDecimal(g); if (compare_omsetexmva != 0) compare_margin = compare_inntjen / compare_omsetexmva; else compare_margin = 0; budgetInfo.comparelist.Add(new BudgetCompareData("compareYear", "MTD i fjor", compare_omset, compare_inntjen, compare_margin)); } // Egen avdeling, siste måned var rowLastMonth = main.database.CallMonthTable(dtTil.AddMonths(-1), main.appConfig.Avdeling).Select(BudgetCategoryClass.GetSqlCategoryString(cat) + " AND (Dato >= '" + dtFra.AddMonths(-1).ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.AddMonths(-1).ToString("yyy-MM-dd") + "')"); DataTable dtLastMonth = rowLastMonth.Any() ? rowLastMonth.CopyToDataTable() : sqlce.Clone(); if (dtLastMonth.Rows.Count > 0) { decimal compare_omset = 0, compare_inntjen = 0, compare_margin = 0, compare_omsetexmva = 0; g = dtLastMonth.Compute("Sum(Salgspris)", ""); if (!DBNull.Value.Equals(g)) compare_omset = Convert.ToDecimal(g); g = dtLastMonth.Compute("Sum(SalgsprisExMva)", ""); if (!DBNull.Value.Equals(g)) compare_omsetexmva = Convert.ToDecimal(g); g = dtLastMonth.Compute("Sum(Btokr)", ""); if (!DBNull.Value.Equals(g)) compare_inntjen = Convert.ToDecimal(g); if (compare_omsetexmva != 0) compare_margin = compare_inntjen / compare_omsetexmva; else compare_margin = 0; budgetInfo.comparelist.Add(new BudgetCompareData("compareMonth", "MTD " + dtTil.AddMonths(-1).ToString("MMMM"), compare_omset, compare_inntjen, compare_margin)); } // Andre avdelinger, opp til 5 favoritter favoritter = FormMain.Favoritter.ToArray(); for (int d = 1; d < favoritter.Length; d++) { if (d > 4) // Max 5 favoritter break; decimal fav_omset = 0, fav_inntjen = 0, fav_margin = 0, fav_omsetexmva = 0; var rowFav = main.database.CallMonthTable(dtTil, favoritter[d]).Select(BudgetCategoryClass.GetSqlCategoryString(cat) + " AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')"); DataTable dtFav = rowFav.Any() ? rowFav.CopyToDataTable() : sqlce.Clone(); g = dtFav.Compute("Sum(Salgspris)", ""); if (!DBNull.Value.Equals(g)) fav_omset = Convert.ToDecimal(g); g = dtFav.Compute("Sum(SalgsprisExMva)", ""); if (!DBNull.Value.Equals(g)) fav_omsetexmva = Convert.ToDecimal(g); g = dtFav.Compute("Sum(Btokr)", ""); if (!DBNull.Value.Equals(g)) fav_inntjen = Convert.ToDecimal(g); if (fav_omsetexmva != 0) fav_margin = fav_inntjen / fav_omsetexmva; else fav_margin = 0; budgetInfo.comparelist.Add(new BudgetCompareData("favorite", favoritter[d], fav_omset, fav_inntjen, fav_margin)); } } // Totalen for alle selgerene string strSel = ""; DataRow[] rows; for (int i = 0; i < budgetInfo.selgere.Count; i++) strSel += " OR Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"; strSel = strSel.Substring(4, strSel.Length - 4); rows = sqlce.Select(strSel + " AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')"); DataTable dtSel = rows.Any() ? rows.CopyToDataTable() : sqlce.Clone(); g = dtSel.Compute("Sum(Salgspris)", ""); if (!DBNull.Value.Equals(g)) Omset_totaltSelgere = Convert.ToDecimal(g); g = dtSel.Compute("Sum(SalgsprisExMva)", ""); if (!DBNull.Value.Equals(g)) OmsetExMva_totaltSelgere = Convert.ToDecimal(g); g = dtSel.Compute("Sum(Btokr)", ""); if (!DBNull.Value.Equals(g)) Inntjen_totaltSelgere = Convert.ToDecimal(g); DataRow dtRow = dtWork.NewRow(); dtRow["Kategori"] = "Overall"; dtRow["Selgerkode"] = "Totalt"; dtRow["Actual_omset"] = Omset_totaltSelgere; dtRow["Actual_inntjen"] = Inntjen_totaltSelgere; dtRow["Actual_omsetExMva"] = Math.Round(OmsetExMva_totaltSelgere, 2); if (OmsetExMva_totaltSelgere != 0) dtRow["Actual_margin"] = Inntjen_totaltSelgere / OmsetExMva_totaltSelgere; else dtRow["Actual_margin"] = 0; dtRow["Target_omset"] = budgetInfo.omsetning * budgetInfo.timeElapsedCoefficient; dtRow["Target_inntjen"] = budgetInfo.inntjening * budgetInfo.timeElapsedCoefficient; dtRow["Target_omsetExMva"] = 0; dtRow["Target_margin"] = budgetInfo.margin; dtRow["Diff_omset"] = Omset_totaltSelgere - (decimal)dtRow["Target_omset"]; dtRow["Diff_inntjen"] = Inntjen_totaltSelgere - (decimal)dtRow["Target_inntjen"]; dtRow["Diff_omsetExMva"] = 0; dtRow["Diff_margin"] = (decimal)dtRow["Actual_margin"] - budgetInfo.margin; dtRow["Sort_value"] = -9999999; for (int i = 0; i < budgetInfo.selgere.Count; i++) { var rowsSel = sqlce.Select("Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "' AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')"); dt = rowsSel.Any() ? rowsSel.CopyToDataTable() : sqlce.Clone(); decimal Omset_selger = 0, OmsetExMva_selger = 0, Inntjen_selger = 0; g = dt.Compute("Sum(Salgspris)", ""); if (!DBNull.Value.Equals(g)) Omset_selger = Convert.ToDecimal(g); g = dt.Compute("Sum(SalgsprisExMva)", ""); if (!DBNull.Value.Equals(g)) OmsetExMva_selger = Convert.ToDecimal(g); g = dt.Compute("Sum(Btokr)", ""); if (!DBNull.Value.Equals(g)) Inntjen_selger = Convert.ToDecimal(g); DataRow dtRowSel = dtWork.NewRow(); dtRowSel["Kategori"] = "Overall"; dtRowSel["Selgerkode"] = budgetInfo.selgere[i].selgerkode; dtRowSel["Actual_omset"] = Omset_selger; dtRowSel["Actual_inntjen"] = Inntjen_selger; dtRowSel["Actual_omsetExMva"] = OmsetExMva_selger; if (OmsetExMva_selger != 0) dtRowSel["Actual_margin"] = Inntjen_selger / OmsetExMva_selger; else dtRowSel["Actual_margin"] = 0; dtRowSel["Target_omset"] = Math.Round(budgetInfo.omsetning * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight, 2); dtRowSel["Target_inntjen"] = Math.Round(budgetInfo.inntjening * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight, 2); dtRowSel["Target_omsetExMva"] = 0; dtRowSel["Target_margin"] = budgetInfo.margin; dtRowSel["Diff_omset"] = Omset_selger - (decimal)dtRowSel["Target_omset"]; dtRowSel["Diff_inntjen"] = Inntjen_selger - (decimal)dtRowSel["Target_inntjen"]; dtRowSel["Diff_omsetExMva"] = Math.Round(OmsetExMva_selger, 2) - (decimal)dtRowSel["Target_omsetExMva"]; dtRowSel["Diff_margin"] = (decimal)dtRowSel["Actual_margin"] - budgetInfo.margin; dtRowSel["Sort_value"] = Inntjen_selger; dtWork.Rows.Add(dtRowSel); budgetInfo.chartdata_inntjen.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, (decimal)dtRowSel["Target_inntjen"], Inntjen_selger)); budgetInfo.chartdata_omset.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, (decimal)dtRowSel["Target_omset"], Omset_selger)); int timer = budgetInfo.selgere[i].timer; if (timer == 0) timer = 1; budgetInfo.chartdata_kvalitet.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, 0, Inntjen_selger / timer)); budgetInfo.chartdata_effektivitet.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, 0, Omset_selger / timer)); } budgetInfo.chartdata_inntjen = budgetInfo.chartdata_inntjen.OrderByDescending(x => x.actual).ToList(); budgetInfo.chartdata_omset = budgetInfo.chartdata_omset.OrderByDescending(x => x.actual).ToList(); budgetInfo.chartdata_kvalitet = budgetInfo.chartdata_kvalitet.OrderByDescending(x => x.actual).ToList(); budgetInfo.chartdata_effektivitet = budgetInfo.chartdata_effektivitet.OrderByDescending(x => x.actual).ToList(); dtWork.Rows.Add(dtRow); DataView dv = dtWork.DefaultView; dv.Sort = "Sort_value desc"; var barchart = new BudgetBarChartData(); barchart.actual_inntjen = Inntjen_totaltSelgere; barchart.actual_omset = Omset_totaltSelgere; if (OmsetExMva_totaltSelgere != 0) barchart.actual_margin = OmsetExMva_totaltSelgere / Inntjen_totaltSelgere; else barchart.actual_margin = 0; barchart.target_inntjen = budgetInfo.inntjening * budgetInfo.timeElapsedCoefficient; barchart.target_omset = budgetInfo.omsetning * budgetInfo.timeElapsedCoefficient; barchart.target_margin = budgetInfo.margin; if (budgetInfo.inntjening != 0) barchart.result_inntjen = Math.Round(Inntjen_totaltSelgere / (budgetInfo.inntjening * budgetInfo.timeElapsedCoefficient) * 100, 2); else barchart.result_inntjen = 0; if (budgetInfo.omsetning != 0) barchart.result_omset = Math.Round(Omset_totaltSelgere / (budgetInfo.omsetning * budgetInfo.timeElapsedCoefficient) * 100, 2); else barchart.result_omset = 0; budgetInfo.barchart = barchart; return dv.ToTable(); } catch (Exception ex) { Log.Unhandled(ex); return null; } }
public void RunBudget(BudgetCategory cat) { if (chkBudgetPicker != pickerBudget.Value && !bwBudget.IsBusy) { HighlightBudgetButton(cat); if (!EmptyDatabase()) { groupBudgetChoices.Enabled = false; bwBudget.RunWorkerAsync(cat); } else webBudget.Navigate(htmlImport); } chkBudgetPicker = rangeMin; }
private BudgetInfo GetBudgetInternal(DateTime date, int budgetId = 0, BudgetCategory cat = BudgetCategory.None) { try { string sql = ""; if (budgetId == 0) sql = "SELECT * FROM tblBudget WHERE Avdeling = " + main.appConfig.Avdeling + " AND Kategori = '" + BudgetCategoryClass.TypeToName(cat) + "' AND datepart(Month, Date) = " + date.Month + " AND datepart(Year, Date) = " + date.Year; else sql = "SELECT * FROM tblBudget WHERE Id = " + budgetId; DataTable dt = main.database.GetSqlDataTable(sql); if (dt.Rows.Count > 0) { var _budgetObj = new BudgetInfo(); // Legg till generell info budgetId = Convert.ToInt32(dt.Rows[0]["Id"].ToString()); _budgetObj.budget_id = budgetId; _budgetObj.date = Convert.ToDateTime(dt.Rows[0]["Date"].ToString()); _budgetObj.dager = Convert.ToInt32(dt.Rows[0]["Dager"].ToString()); _budgetObj.avdeling = Convert.ToInt32(dt.Rows[0]["Avdeling"].ToString()); _budgetObj.kategori = BudgetCategoryClass.NameToType(dt.Rows[0]["Kategori"].ToString()); _budgetObj.omsetning = Convert.ToDecimal(dt.Rows[0]["Omsetning"].ToString()); _budgetObj.inntjening = Convert.ToDecimal(dt.Rows[0]["Inntjening"].ToString()); _budgetObj.margin = Convert.ToDecimal(dt.Rows[0]["Margin"].ToString()); _budgetObj.ta = Convert.ToDecimal(dt.Rows[0]["TA"].ToString()); _budgetObj.ta_type = ConvertToBudgetType(dt.Rows[0]["TA_Type"].ToString()); _budgetObj.strom = Convert.ToDecimal(dt.Rows[0]["Strom"].ToString()); _budgetObj.strom_type = ConvertToBudgetType(dt.Rows[0]["Strom_Type"].ToString()); _budgetObj.finans = Convert.ToDecimal(dt.Rows[0]["Finans"].ToString()); _budgetObj.finans_type = ConvertToBudgetType(dt.Rows[0]["Finans_Type"].ToString()); _budgetObj.rtgsa = Convert.ToDecimal(dt.Rows[0]["Rtgsa"].ToString()); _budgetObj.rtgsa_type = ConvertToBudgetType(dt.Rows[0]["Rtgsa_Type"].ToString()); _budgetObj.acc = Convert.ToDecimal(dt.Rows[0]["Acc"].ToString()); _budgetObj.acc_type = ConvertToBudgetType(dt.Rows[0]["Acc_Type"].ToString()); _budgetObj.vinn = Convert.ToDecimal(dt.Rows[0]["Vinn"].ToString()); _budgetObj.vinn_type = ConvertToBudgetType(dt.Rows[0]["Vinn_Type"].ToString()); _budgetObj.updated = Convert.ToDateTime(dt.Rows[0]["Updated"].ToString()); // Legg til selgere under dette budsjettet DataTable dtSel = main.database.GetSqlDataTable("SELECT Selgerkode, Timer, Dager, Multiplikator FROM tblBudgetSelger WHERE BudgetId = " + budgetId); if (dtSel.Rows.Count > 0) { List<BudgetSelger> list = new List<BudgetSelger>() { }; int timer = 0, dager = 0; for(int i = 0; i < dtSel.Rows.Count; i++) { BudgetSelger bselger = new BudgetSelger(); bselger.selgerkode = dtSel.Rows[i]["Selgerkode"].ToString(); bselger.timer = Convert.ToInt32(dtSel.Rows[i]["Timer"]); timer += bselger.timer; bselger.dager = Convert.ToInt32(dtSel.Rows[i]["Dager"]); dager += bselger.dager; bselger.multiplikator = Convert.ToDecimal(dtSel.Rows[i]["Multiplikator"]); list.Add(bselger); } _budgetObj.totalt_timer = timer; _budgetObj.totalt_dager = dager; for (int i = 0; i < list.Count; i++ ) { decimal weight = 0; if (timer > 0) weight = (list[i].timer * list[i].multiplikator) / timer; list[i].weight = weight; } _budgetObj.selgere = list; } // Regne ut coefficient tall for beregning av budsjett MTD decimal daysElapsed = GetNumberOfOpenDaysInMonth(FormMain.GetFirstDayOfMonth(date), date); decimal daysInMonth = _budgetObj.dager; _budgetObj.timeElapsedCoefficient = daysElapsed / daysInMonth; _budgetObj.daysElapsed = (int)daysElapsed; return _budgetObj; } } catch (Exception ex) { Log.Unhandled(ex); } return null; }
private bool CheckDuplicate(int avdeling, BudgetCategory cat, DateTime date) { var con = new SqlCeConnection(FormMain.SqlConStr); con.Open(); SqlCeCommand cmd = con.CreateCommand(); cmd.CommandText = "SELECT COUNT(*) FROM tblBudget WHERE Avdeling = " + avdeling + " AND Kategori = '" + BudgetCategoryClass.TypeToName(cat) + "' AND datepart(Month, Date) = " + date.Month + " AND datepart(Year, Date) = " + date.Year; int result = ((int)cmd.ExecuteScalar()); con.Close(); con.Dispose(); if (result == 0) return false; return true; }
public string[] GetBudgetSelgerkoder(BudgetCategory cat) { if (dtCache == null) dtCache = main.database.GetSqlDataTable("SELECT * FROM tblSelgerkoder WHERE Avdeling = '" + main.appConfig.Avdeling + "'"); List<string> selgere = new List<string>(); string name = BudgetCategoryClass.TypeToName(cat); if (cat == BudgetCategory.Butikk) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() != "Teknikere" || dtCache.Rows[i]["Kategori"].ToString() != "Aftersales") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } else { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == name) selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } if (cat == BudgetCategory.Aftersales) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "Teknikere") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } if (cat == BudgetCategory.MDASDA) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "MDA" || dtCache.Rows[i]["Kategori"].ToString() == "SDA") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } if (main.appConfig.budgetInclAllSalesRepUnderCross && cat == BudgetCategory.Cross) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "AudioVideo" || dtCache.Rows[i]["Kategori"].ToString() == "Tele" || dtCache.Rows[i]["Kategori"].ToString() == "Data") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } if (!main.appConfig.budgetIsolateCrossSalesRep && (cat == BudgetCategory.AudioVideo || cat == BudgetCategory.Tele || cat == BudgetCategory.Data)) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "Cross") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } string[] sk = selgere.ToArray(); return sk; }
public string[] GetVinnSelgerkoder(BudgetCategory cat) { if (dtCache == null) dtCache = main.database.GetSqlDataTable("SELECT * FROM tblSelgerkoder WHERE Avdeling = '" + main.appConfig.Avdeling + "'"); List<string> selgere = new List<string>(); if (cat == BudgetCategory.MDASDA) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "MDA" || dtCache.Rows[i]["Kategori"].ToString() == "SDA") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } else if (cat == BudgetCategory.Cross) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "AudioVideo" || dtCache.Rows[i]["Kategori"].ToString() == "Tele" || dtCache.Rows[i]["Kategori"].ToString() == "Data" || dtCache.Rows[i]["Kategori"].ToString() == "Cross") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } else if (cat == BudgetCategory.Kasse) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "Kasse") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } else if (cat == BudgetCategory.Aftersales) { for (int i = 0; i < dtCache.Rows.Count; i++) if (dtCache.Rows[i]["Kategori"].ToString() == "Aftersales" || dtCache.Rows[i]["Kategori"].ToString() == "Teknikere") selgere.Add(dtCache.Rows[i]["Selgerkode"].ToString()); } string[] sk = selgere.ToArray(); return sk; }
public void MakeBudgetPage(BudgetCategory cat, BackgroundWorker bw = null) { string newHash = appConfig.Avdeling + pickerBudget.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString(); if (cat == BudgetCategory.MDA) { BuildBudget(cat, appConfig.strBudgetMda, htmlBudgetMda); appConfig.strBudgetMda = newHash; } else if (cat == BudgetCategory.AudioVideo) { BuildBudget(cat, appConfig.strBudgetAv, htmlBudgetAudioVideo); appConfig.strBudgetAv = newHash; } else if (cat == BudgetCategory.SDA) { BuildBudget(cat, appConfig.strBudgetSda, htmlBudgetSda); appConfig.strBudgetSda = newHash; } else if (cat == BudgetCategory.Tele) { BuildBudget(cat, appConfig.strBudgetTele, htmlBudgetTele); appConfig.strBudgetTele = newHash; } else if (cat == BudgetCategory.Data) { BuildBudget(cat, appConfig.strBudgetData, htmlBudgetData); appConfig.strBudgetData = newHash; } else if (cat == BudgetCategory.Cross) { BuildBudget(cat, appConfig.strBudgetCross, htmlBudgetCross); appConfig.strBudgetCross = newHash; } else if (cat == BudgetCategory.Kasse) { BuildBudget(cat, appConfig.strBudgetKasse, htmlBudgetKasse); appConfig.strBudgetKasse = newHash; } else if (cat == BudgetCategory.Aftersales) { BuildBudget(cat, appConfig.strBudgetAftersales, htmlBudgetAftersales); appConfig.strBudgetAftersales = newHash; } else if (cat == BudgetCategory.MDASDA) { BuildBudget(cat, appConfig.strBudgetMdasda, htmlBudgetMdasda); appConfig.strBudgetMdasda = newHash; } else if (cat == BudgetCategory.Butikk) { BuildBudget(cat, appConfig.strBudgetButikk, htmlBudgetButikk); appConfig.strBudgetButikk = newHash; } else if (cat == BudgetCategory.Daglig) { PageBudgetDaily page = new PageBudgetDaily(this, false, bw, webBudget); page.BuildPage(cat, appConfig.strBudgetDaily, htmlBudgetDaily, pickerBudget.Value); appConfig.strBudgetDaily = newHash; } else Log.n("Ingen kategori valgt for beregning av budsjett."); }
public List<string> GetTableHtml(BudgetCategory cat, BackgroundWorker bw = null) { try { var doc = new List<string>(); if (StopRankingPending()) return doc; var hashId = random.Next(999, 99999); string urlID = "link"; doc.Add("<br>"); dtBudgetOverall = MakeTableBudget(cat); if (dtBudgetOverall.Rows.Count == 0) { doc.Add("<span class='Subtitle' style='color:red !important;'>Fant ingen transaksjoner.</span><br>"); return doc; } DateTime date = dtTil; if (date > main.appConfig.dbTo) date = main.appConfig.dbTo; doc.Add("<h3>Resultat for " + BudgetCategoryClass.TypeToName(cat) + " budsjett oppdatert " + date.ToString("dddd d. MMMM yyyy", FormMain.norway) + " og timeantall oppdatert " + budgetInfo.updated.ToString("dddd d. MMMM yyyy", FormMain.norway) + "</h2>"); doc.Add("<div class='toolbox hidePdf'>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>"); doc.Add("</div>"); doc.Add("<table class='" + outerclass + " toggleAll' id='" + hashId + "'><tr><td>"); doc.Add("<table style='font: bold 12px/18px Arial, Sans-serif;' >"); doc.Add("<tr><td style='background-color:#D9D9D9;text-align:center;padding: 0px 5px 0px 5px;' width=124 >" + BudgetCategoryClass.TypeToName(cat).ToUpper() + "</td>"); doc.Add("<td style='background-color:#ff5b2e;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=282 >Resultat</td>"); doc.Add("<td style='background-color:#1163b0;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=237 >MÃ¥l</td>"); doc.Add("<td style='background-color:orange;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=242 >Differanse</td>"); doc.Add("</tr>"); doc.Add("</table>"); doc.Add("<table class='tablesorter'>"); doc.Add("<thead><tr>"); doc.Add("<th class=\"{sorter: 'text'}\" width=130 >Selgerkode</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='border-left:1px solid black;background-color:#ff5b2e;' width=95 >Omset.</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='background-color:#ff5b2e;' width=95 >Inntjen.</td>"); doc.Add("<th class=\"{sorter: 'procent'}\" style='background-color:#ff5b2e;' width=90 >Margin</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='border-left:1px solid black;background-color:#1163b0;' width=80 >Omset.</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='background-color:#1163b0;' width=80 >Inntjen.</td>"); doc.Add("<th class=\"{sorter: 'procent'}\" style='background-color:#1163b0;' width=75 >Margin</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='border-left:1px solid black;background-color:orange;' width=80 >Omset.</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='background-color:orange;' width=80 >Inntjen.</td>"); doc.Add("<th class=\"{sorter: 'procent'}\" style='background-color:orange;' width=80 >Margin</td>"); doc.Add("</tr></thead>"); doc.Add("<tbody>"); for (int i = 0; i < dtBudgetOverall.Rows.Count; i++) { string strLine = dtBudgetOverall.Rows[i]["Selgerkode"].ToString() == "Totalt" ? " style='border-top:2px solid black;' " : ""; if (dtBudgetOverall.Rows[i]["Selgerkode"].ToString() == "Totalt") doc.Add("</tbody><tfoot><tr><td class='text-cat' " + strLine + ">" + main.salesCodes.GetNavn(dtBudgetOverall.Rows[i]["Selgerkode"].ToString()) + "</td>"); else doc.Add("<tr><td class='text-cat' " + strLine + "><a href='#" + urlID + "b" + dtBudgetOverall.Rows[i]["Selgerkode"].ToString() + "'>" + main.salesCodes.GetNavn(dtBudgetOverall.Rows[i]["Selgerkode"].ToString()) + "</a></td>"); doc.Add("<td class='numbers-gen'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Actual_Omset"]) + "</td>"); doc.Add("<td class='numbers-gen'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Actual_Inntjen"]) + "</td>"); doc.Add("<td class='numbers-percent'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Actual_Margin"] * 100, 2, false, " %") + "</td>"); doc.Add("<td class='numbers-gen'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Target_Omset"]) + "</td>"); doc.Add("<td class='numbers-gen'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Target_Inntjen"]) + "</td>"); doc.Add("<td class='numbers-percent'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Target_Margin"] * 100, 2, false, " %") + "</td>"); doc.Add("<td class='numbers-gen'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Diff_Omset"], 0, true) + "</td>"); doc.Add("<td class='numbers-gen'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Diff_Inntjen"], 0, true) + "</td>"); doc.Add("<td class='numbers-percent'" + strLine + ">" + budget.BudgetPlusMinus((decimal)dtBudgetOverall.Rows[i]["Diff_Margin"] * 100, 2, true, " %") + "</td>"); doc.Add("</tr>"); } doc.Add("</tfoot>"); if (budgetInfo.comparelist != null) { // Detailed look START doc.Add("<tfoot><tr><td colspan='5' style='padding: 0px 0px 0px 0px;border:none;'>"); doc.Add("<table class='tablesorter'><thead><tr>"); doc.Add("<th class=\"{sorter: 'text'}\" style='border-top:#000 1px solid;border-left:#000 1px solid;' width=160 >Avdeling (" + BudgetCategoryClass.TypeToName(cat) + ")</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='border-top:#000 1px solid;' width=103 >Omset.</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" style='border-top:#000 1px solid;' width=103 >Inntjen.</td>"); doc.Add("<th class=\"{sorter: 'procent'}\" style='border-top:#000 1px solid;border-right:#000 1px solid;' width=94 >Margin</td>"); doc.Add("</tr></thead><tbody>"); for (int i = 0; i < budgetInfo.comparelist.Count; i++) { if (budgetInfo.comparelist[i].type == "favorite") doc.Add("<tr><td class='text-cat' style='border-bottom: #ccc 1px solid;border-left: #ccc 1px solid;'>" + avdeling.Get(Convert.ToInt32(budgetInfo.comparelist[i].navn)).Replace(" ", " ") + "</td>"); else doc.Add("<tr><td class='text-cat' style='border-bottom: #ccc 1px solid;border-left: #ccc 1px solid;'>" + budgetInfo.comparelist[i].navn + "</td>"); doc.Add("<td class='numbers-gen' style='border-bottom: #ccc 1px solid;'>" + budget.BudgetPlusMinus((decimal)budgetInfo.comparelist[i].omset) + "</td>"); doc.Add("<td class='numbers-gen' style='border-bottom: #ccc 1px solid;'>" + budget.BudgetPlusMinus((decimal)budgetInfo.comparelist[i].inntjen) + "</td>"); doc.Add("<td class='numbers-percent' style='border-bottom: #ccc 1px solid;border-right: #ccc 1px solid;'>" + budget.BudgetPlusMinus((decimal)budgetInfo.comparelist[i].margin * 100, 2, false, " %") + "</td></tr>"); } doc.Add("</tr></body></table>"); budget.SaveBarChartImage(FormMain.settingsPath + @"\graphBudgetOverall" + BudgetCategoryClass.TypeToName(cat) + ".png", budgetInfo); doc.Add("</td><td colspan='5' style='padding: 0px 0px 0px 0px;border:none;'><img src='graphBudgetOverall" + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:410px;height:auto;'></td></tr>"); doc.Add("</tfoot>"); // Detailed look END } doc.Add("</table>"); doc.Add("</td></tr></table>"); decimal count = budgetInfo.selgere.Count; if (count < main.appConfig.budgetChartMinPosts) count = main.appConfig.budgetChartMinPosts; decimal chartHeight = 100 + main.appConfig.budgetChartPostWidth * count; hashId = random.Next(999, 99999); doc.Add("<div class='toolbox hidePdf'>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>"); doc.Add("</div>"); doc.Add("<div class='no-break'>"); doc.Add("<h3>Inntjening</h3>"); doc.Add("<table class='toggleAll' style='background-color:white;border:1px solid black;' id='" + hashId + "'><tr><td>"); budget.SaveChartImage(main.appConfig.graphResX, (int)chartHeight, FormMain.settingsPath + @"\graphBudgetInntjen" + BudgetCategoryClass.TypeToName(cat) + ".png", BudgetValueType.Inntjening, BudgetType.Inntjening, budgetInfo.chartdata_inntjen); doc.Add("<img src='graphBudgetInntjen" + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:900px;height:auto;'><br>"); doc.Add("</td></tr></table>"); doc.Add("</div>"); doc.Add("<div class='no-break'>"); doc.Add("<h3>Omsetning</h3>"); doc.Add("<table class='toggleAll' style='background-color:white;border:1px solid black;' id='" + hashId + "'><tr><td>"); budget.SaveChartImage(main.appConfig.graphResX, (int)chartHeight, FormMain.settingsPath + @"\graphBudgetOmset" + BudgetCategoryClass.TypeToName(cat) + ".png", BudgetValueType.Omsetning, BudgetType.Omsetning, budgetInfo.chartdata_omset); doc.Add("<img src='graphBudgetOmset" + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:900px;height:auto;'><br>"); doc.Add("</td></tr></table>"); doc.Add("</div>"); if (main.appConfig.budgetChartShowEfficiency || main.appConfig.budgetChartShowQuality) { hashId = random.Next(999, 99999); doc.Add("<div class='toolbox hidePdf'>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>"); doc.Add("</div>"); if (main.appConfig.budgetChartShowQuality) { doc.Add("<div class='no-break'>"); doc.Add("<h3>Kvalitet: Inntjening pr. time</h3>"); doc.Add("<table class='toggleAll' style='background-color:white;border:1px solid black;' id='" + hashId + "'><tr><td>"); budget.SaveChartImage(main.appConfig.graphResX, (int)chartHeight, FormMain.settingsPath + @"\graphBudgetKvalitet" + BudgetCategoryClass.TypeToName(cat) + ".png", BudgetValueType.Inntjening, BudgetType.Kvalitet, budgetInfo.chartdata_kvalitet); doc.Add("<img src='graphBudgetKvalitet" + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:900px;height:auto;'><br>"); doc.Add("</td></tr></table>"); doc.Add("</div>"); } if (main.appConfig.budgetChartShowEfficiency) { doc.Add("<div class='no-break'>"); doc.Add("<h3>Effektivitet: Omsetning pr. time</h3>"); doc.Add("<table class='toggleAll' style='background-color:white;border:1px solid black;' id='" + hashId + "'><tr><td>"); budget.SaveChartImage(main.appConfig.graphResX, (int)chartHeight, FormMain.settingsPath + @"\graphBudgetEffektivitet" + BudgetCategoryClass.TypeToName(cat) + ".png", BudgetValueType.Omsetning, BudgetType.Effektivitet, budgetInfo.chartdata_effektivitet); doc.Add("<img src='graphBudgetEffektivitet" + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:900px;height:auto;'><br>"); doc.Add("</td></tr></table>"); doc.Add("</div>"); } } return doc; } catch (Exception ex) { Log.Unhandled(ex); return null; } }
public List<string> GetTableHtml(BudgetCategory cat) { try { var doc = new List<string>() { }; var hashId = random.Next(999, 99999); string filter = "Kategori = '" + BudgetCategoryClass.TypeToName(cat) + "'"; if (cat == BudgetCategory.None) filter = ""; var rows = tableVinn.Select(filter); DataTable dtVinn = rows.Any() ? rows.CopyToDataTable() : sqlce.Clone(); if (dtVinn.Rows.Count > 0) dt = dtVinn; else { doc.Add("<span class='Subtitle' style='color:red !important;'>Fant ingen transaksjoner.</span><br>"); return doc; } main.openXml.SaveDocument(dt, "Vinnprodukter", BudgetCategoryClass.TypeToName(cat), dtPick, BudgetCategoryClass.TypeToName(cat).ToUpper() + " - " + dtPick.ToString("dddd d. MMMM yyyy", norway)); doc.Add("<div class='toolbox hidePdf'>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>"); doc.Add("</div>"); doc.Add("<div style=\"width:100%;\" id='" + hashId + "' class='toggleAll'>"); doc.Add("<table class='tblBestOf'><tr><td>"); doc.Add("<table class='tablesorter'>"); doc.Add("<thead><tr>"); doc.Add("<th class=\"{sorter: 'text'}\" width=\"210\" style='background:#f04c4d;'>Selger</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" width=\"200\" style='background:#f04c4d;'> </td>"); if (main.appConfig.vinnEnkelModus) { doc.Add("<th class=\"{sorter: 'digit'}\" width=\"180\" style='background:#f04c4d;'>Antall</td>"); } else { doc.Add("<th class=\"{sorter: 'digit'}\" width=\"110\" style='background:#f04c4d;'>Poeng</td>"); doc.Add("<th class=\"{sorter: 'digit'}\" width=\"100\" style='background:#f04c4d;'>Antall</td>"); } doc.Add("<th class=\"{sorter: 'digit'}\" width=\"120\" style='background:#f04c4d;'>Inntjen</td>"); if (main.appConfig.vinnSisteDagVare) doc.Add("<th class=\"{sorter: 'text'}\" width=\"210\" style='background:#f04c4d;'>Mest solgt sist dag</td>"); else doc.Add("<th class=\"{sorter: 'text'}\" width=\"210\" style='background:#f04c4d;'>Mest solgt</td>"); doc.Add("</tr></thead>"); doc.Add("<tbody>"); decimal height = 5; for (int i = 0; i < dt.Rows.Count; i++) { height++; string strLine = dt.Rows.Count == i - 1 ? "border-bottom:none;" : ""; doc.Add("<tr><td class='text-cat' style='font-size:14pt;" + strLine + "'><a href='#vinn" + dt.Rows[i]["Selgerkode"].ToString() + "'>" + main.salesCodes.GetNavn(dt.Rows[i]["Selgerkode"].ToString()) + "</a></td>"); if (main.appConfig.vinnEnkelModus) { doc.Add("<td class='numbers-small' style='font-size:14pt;" + strLine + ShowGraph((decimal)dt.Rows[i]["Vinn_Poeng"], vinn_max) + strLine + "'> </td>"); doc.Add("<td class='numbers-gen' style='font-size:14pt;" + strLine + "'>" + LastOpenDayString(dt.Rows[i]["Vinn_SisteDagPoeng"]) + ForkortTall(Convert.ToDecimal(dt.Rows[i]["Vinn_Poeng"])) + "</td>"); } else { doc.Add("<td class='numbers-small' style='font-size:14pt;" + strLine + ShowGraph((decimal)dt.Rows[i]["Vinn_Poeng"], vinn_max) + strLine + "'> </td>"); doc.Add("<td class='numbers-gen' style='font-size:14pt;" + strLine + "'>" + LastOpenDayString(dt.Rows[i]["Vinn_SisteDagPoeng"]) + ForkortTall(Convert.ToDecimal(dt.Rows[i]["Vinn_Poeng"])) + "</td>"); doc.Add("<td class='numbers-small' style='font-size:14pt;" + strLine + "'>" + ForkortTall(Convert.ToDecimal(dt.Rows[i]["Vinn_Antall"])) + "</td>"); } doc.Add("<td class='numbers-gen' style='font-size:14pt;" + strLine + "'>" + ForkortTall(Convert.ToDecimal(dt.Rows[i]["Vinn_Inntjen"])) + "</td>"); if (main.appConfig.vinnSisteDagVare && !DBNull.Value.Equals(dt.Rows[i]["Vinn_SisteDagVare"])) doc.Add("<td class='numbers-percent' style='font-size:14pt;" + strLine + "'>" + dt.Rows[i]["Vinn_SisteDagVare"].ToString().ToUpper() + "</td>"); else if (main.appConfig.vinnSisteDagVare && DBNull.Value.Equals(dt.Rows[i]["Vinn_SisteDagVare"])) doc.Add("<td class='numbers-percent' style='font-size:14pt;" + strLine + "'> </td>"); else doc.Add("<td class='numbers-percent' style='font-size:14pt;" + strLine + "'>" + dt.Rows[i]["Vinn_FavorittProd"].ToString().ToUpper() + "</td>"); doc.Add("</tr>"); } doc.Add("</tfoot>"); doc.Add("</table></td></tr></table>"); return doc; } catch(Exception ex) { Log.Unhandled(ex); } return new List<string>() { }; ; }
public List<string> GetTableHtmlProduct(BudgetCategory cat, BudgetType product) { try { var doc = new List<string>(); if (StopRankingPending()) return doc; var hashId = random.Next(999, 99999); string urlID = "link"; doc.Add("<br>"); doc.Add("<a name='" + budget.ProductToString(product) + "'></a>"); budgetInfo = budget.GetBudgetInfo(dtTil, cat); if (budgetInfo == null) { doc.Add("<span class='Subtitle' style='color:red !important;'>Budsjett for " + BudgetCategoryClass.TypeToName(cat) + " mangler for valgt måned.</span><br>"); return doc; } if (budgetInfo.selgere.Count == 0) { doc.Add("<span class='Subtitle' style='color:red !important;'>Ingen selgerkoder er satt opp for " + BudgetCategoryClass.TypeToName(cat) + " budsjettet.</span><br>"); return doc; } BudgetValueType type = budgetInfo.ProductToType(product); DataTable dtBudgetProduct = MakeTableBudgetProduct(cat, product, type); string productColor = budget.GetProductColor(product); DateTime date = dtTil; if (date > main.appConfig.dbTo) date = main.appConfig.dbTo; doc.Add("<h2>Resultat for " + budget.ProductToString(product) + " - " + BudgetCategoryClass.TypeToName(cat) + " budsjett oppdatert " + date.ToString("dddd d. MMMM yyyy", FormMain.norway) + " og timeantall oppdatert " + budgetInfo.updated.ToString("dddd d. MMMM yyyy", FormMain.norway) + "</h2>"); doc.Add("<div class='toolbox hidePdf'>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>"); doc.Add("</div>"); doc.Add("<table class='" + outerclass + " toggleAll' id='" + hashId + "'><tr><td>"); doc.Add("<table style='font: bold 12px/18px Arial, Sans-serif;' >"); doc.Add("<tr><td style='background-color:#D9D9D9;text-align:center;padding: 0px 5px 0px 5px;' width=144 >" + BudgetCategoryClass.TypeToName(cat).ToUpper() + "</td>"); doc.Add("<td style='background-color:" + productColor + ";text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=362 >Resultat</td>"); doc.Add("<td style='background-color:#1163b0;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=208 >Mål</td>"); doc.Add("<td style='background-color:orange;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=188 >Differanse</td>"); doc.Add("</tr>"); doc.Add("</table>"); doc.Add("<table class='tablesorter'>"); doc.Add("<thead><tr>"); doc.Add("<th class=\"{sorter: 'text'}\" width=150 >" + budget.ProductToString(product) + "</td>"); KgsaBudgetProduct proActual = (KgsaBudgetProduct)dtBudgetProduct.Rows[0]["Field1"]; doc.Add("<th class=\"{sorter: '" + proActual.fields[0].sorter + "'}\" style='border-left:1px solid black;background-color:" + productColor + ";' width=130 >" + proActual.fields[0].header + "</td>"); doc.Add("<th class=\"{sorter: '" + proActual.fields[1].sorter + "'}\" style='background-color:" + productColor + ";' width=130 >" + proActual.fields[1].header + "</td>"); doc.Add("<th class=\"{sorter: '" + proActual.fields[2].sorter + "'}\" style='background-color:" + productColor + ";' width=100 >" + proActual.fields[2].header + "</td>"); KgsaBudgetProduct proTarget = (KgsaBudgetProduct)dtBudgetProduct.Rows[0]["Field2"]; doc.Add("<th class=\"{sorter: '" + proTarget.fields[0].sorter + "'}\" style='border-left:1px solid black;background-color:#1163b0;' width=120 >" + proTarget.fields[0].header + "</td>"); doc.Add("<th class=\"{sorter: '" + proTarget.fields[1].sorter + "'}\" style='background-color:#1163b0;' width=90 >" + proTarget.fields[1].header + "</td>"); KgsaBudgetProduct proDiff = (KgsaBudgetProduct)dtBudgetProduct.Rows[0]["Field3"]; doc.Add("<th class=\"{sorter: '" + proDiff.fields[0].sorter + "'}\" style='border-left:1px solid black;background-color:orange;' width=100 >" + proDiff.fields[0].header + "</td>"); doc.Add("<th class=\"{sorter: '" + proDiff.fields[1].sorter + "'}\" style='background-color:orange;' width=90 >" + proDiff.fields[1].header + "</td>"); doc.Add("</tr></thead>"); doc.Add("<tbody>"); string sorterStyle = type == BudgetValueType.Antall || type == BudgetValueType.Inntjening || type == BudgetValueType.Omsetning ? "numbers-gen" : "percent"; for (int i = 0; i < dtBudgetProduct.Rows.Count; i++) { string strLine = dtBudgetOverall.Rows[i]["Selgerkode"].ToString() == "Totalt" ? " style='border-top:2px solid black;border-bottom:none;' " : ""; if (dtBudgetOverall.Rows[i]["Selgerkode"].ToString() == "Totalt") doc.Add("</tbody><tfoot><tr><td class='text-cat' " + strLine + ">" + main.salesCodes.GetNavn(dtBudgetProduct.Rows[i]["Selgerkode"].ToString()) + "</td>"); else doc.Add("<tr><td class='text-cat' " + strLine + "><a href='#" + urlID + "b" + dtBudgetProduct.Rows[i]["Selgerkode"].ToString() + "'>" + main.salesCodes.GetNavn(dtBudgetProduct.Rows[i]["Selgerkode"].ToString()) + "</a></td>"); proActual = (KgsaBudgetProduct)dtBudgetProduct.Rows[i]["Field1"]; doc.Add("<td class='" + proActual.fields[0].style + "'" + strLine + ">" + proActual.fields[0].text + "</td>"); doc.Add("<td class='" + proActual.fields[1].style + "'" + strLine + ">" + proActual.fields[1].text + "</td>"); doc.Add("<td class='" + proActual.fields[2].style + "'" + strLine + ">" + proActual.fields[2].text + "</td>"); proTarget = (KgsaBudgetProduct)dtBudgetProduct.Rows[i]["Field2"]; doc.Add("<td class='" + proTarget.fields[0].style + "'" + strLine + ">" + proTarget.fields[0].text + "</td>"); doc.Add("<td class='" + proTarget.fields[1].style + "'" + strLine + ">" + proTarget.fields[1].text + "</td>"); proDiff = (KgsaBudgetProduct)dtBudgetProduct.Rows[i]["Field3"]; doc.Add("<td class='" + proDiff.fields[0].style + "'" + strLine + ">" + proDiff.fields[0].text + "</td>"); doc.Add("<td class='" + proDiff.fields[1].style + "'" + strLine + ">" + proDiff.fields[1].text + "</td>"); doc.Add("</tr>"); } doc.Add("</tfoot></table>"); doc.Add("</td></tr></table>"); decimal count = budgetInfo.selgere.Count; if (count < main.appConfig.budgetChartMinPosts) count = main.appConfig.budgetChartMinPosts; decimal chartHeight = 100 + main.appConfig.budgetChartPostWidth * count; hashId = random.Next(999, 99999); doc.Add("<div class='toolbox hidePdf'>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>"); doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>"); doc.Add("</div>"); doc.Add("<div class='no-break'>"); doc.Add("<h3>" + budget.ProductToString(product) + "</h3>"); doc.Add("<table class='toggleAll' style='background-color:white;border:1px solid black;' id='" + hashId + "'><tr><td>"); budget.SaveChartImage(main.appConfig.graphResX, (int)chartHeight, FormMain.settingsPath + @"\graphBudget" + product + BudgetCategoryClass.TypeToName(cat) + ".png", type, product, budgetInfo.chartdata); doc.Add("<img src='graphBudget" + product + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:900px;height:auto;'><br>"); doc.Add("</td></tr></table>"); doc.Add("</div>"); return doc; } catch (Exception ex) { Log.Unhandled(ex); return null; } }
public int AddBudget(int avdeling, BudgetCategory cat, DateTime date, int dager, decimal omsetning, decimal inntjening, decimal margin, decimal ta_value = 0, string ta_type = "SOB", decimal strom_value = 0, string strom_type = "Antall", decimal finans_value = 0, string finans_type = "SOM", decimal rtgsa_value = 0, string rtgsa_type = "Hitrate", decimal acc_value = 0, string acc_type = "SOM", decimal vinn_value = 0, string vinn_type = "Poeng", bool update = false, int id = 0) { try { var con = new SqlCeConnection(FormMain.SqlConStr); con.Open(); if (CheckDuplicate(avdeling, cat, date) && !update) { Log.n("Budsjett: Dette budsjettet finnes allerede i databasen. Slett den gamle først hvis du mener å lage en ny."); return -1; } if (update) { using (SqlCeCommand cmd = new SqlCeCommand("UPDATE tblBudget SET " + "Avdeling=@Avdeling,Kategori=@Kategori,Date=@Date,Dager=@Dager,Omsetning=@Omsetning,Inntjening=@Inntjening,Margin=@Margin," + "TA=@TA,TA_Type=@TA_Type,Strom=@Strom,Strom_Type=@Strom_Type,Finans=@Finans,Finans_Type=@Finans_Type,Rtgsa=@Rtgsa,Acc=@Acc,Acc_Type=@Acc_Type,Vinn=@Vinn,Vinn_Type=@Vinn_Type,Updated=@Updated" + " WHERE Id=@Id", con)) { cmd.Parameters.AddWithValue("@Id", id); cmd.Parameters.AddWithValue("@Avdeling", avdeling); cmd.Parameters.AddWithValue("@Kategori", BudgetCategoryClass.TypeToName(cat)); cmd.Parameters.AddWithValue("@Date", date); cmd.Parameters.AddWithValue("@Dager", dager); cmd.Parameters.AddWithValue("@Omsetning", omsetning); cmd.Parameters.AddWithValue("@Inntjening", inntjening); cmd.Parameters.AddWithValue("@Margin", margin); cmd.Parameters.AddWithValue("@TA", ta_value); cmd.Parameters.AddWithValue("@TA_Type", ta_type); cmd.Parameters.AddWithValue("@Strom", strom_value); cmd.Parameters.AddWithValue("@Strom_Type", strom_type); cmd.Parameters.AddWithValue("@Finans", finans_value); cmd.Parameters.AddWithValue("@Finans_Type", finans_type); cmd.Parameters.AddWithValue("@Rtgsa", rtgsa_value); cmd.Parameters.AddWithValue("@Rtgsa_Type", rtgsa_type); cmd.Parameters.AddWithValue("@Acc", acc_value); cmd.Parameters.AddWithValue("@Acc_Type", acc_type); cmd.Parameters.AddWithValue("@Vinn", vinn_value); cmd.Parameters.AddWithValue("@Vinn_Type", vinn_type); cmd.Parameters.AddWithValue("@Updated", date); cmd.CommandType = System.Data.CommandType.Text; cmd.ExecuteNonQuery(); } } else { using (SqlCeCommand cmd = new SqlCeCommand("INSERT INTO tblBudget(Avdeling, Kategori, Date, Dager, Omsetning, Inntjening, Margin, TA, TA_Type, Strom, Strom_Type, Finans, Finans_Type, Rtgsa, Rtgsa_Type, Acc, Acc_Type, Vinn, Vinn_Type, Updated) values (@Val1, @Val2, @Val3, @Val4, @Val5, @Val6, @Val7, @Val8, @Val9, @Val10, @Val11, @Val12, @Val13, @Val14, @Val15, @Val16, @Val17, @Val18, @Val19, @Val20)", con)) { cmd.Parameters.AddWithValue("@Val1", avdeling); cmd.Parameters.AddWithValue("@Val2", BudgetCategoryClass.TypeToName(cat)); cmd.Parameters.AddWithValue("@Val3", date); cmd.Parameters.AddWithValue("@Val4", dager); cmd.Parameters.AddWithValue("@Val5", omsetning); cmd.Parameters.AddWithValue("@Val6", inntjening); cmd.Parameters.AddWithValue("@Val7", margin); cmd.Parameters.AddWithValue("@Val8", ta_value); cmd.Parameters.AddWithValue("@Val9", ta_type); cmd.Parameters.AddWithValue("@Val10", strom_value); cmd.Parameters.AddWithValue("@Val11", strom_type); cmd.Parameters.AddWithValue("@Val12", finans_value); cmd.Parameters.AddWithValue("@Val13", finans_type); cmd.Parameters.AddWithValue("@Val14", rtgsa_value); cmd.Parameters.AddWithValue("@Val15", rtgsa_type); cmd.Parameters.AddWithValue("@Val16", acc_value); cmd.Parameters.AddWithValue("@Val17", acc_type); cmd.Parameters.AddWithValue("@Val18", vinn_value); cmd.Parameters.AddWithValue("@Val19", vinn_type); cmd.Parameters.AddWithValue("@Val20", FormMain.GetFirstDayOfMonth(date)); cmd.CommandType = System.Data.CommandType.Text; cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT @@IDENTITY"; id = Convert.ToInt32(cmd.ExecuteScalar()); } } con.Close(); con.Dispose(); return id; } catch(Exception ex) { Log.Unhandled(ex); } return -1; }
public static string TypeToName(BudgetCategory cat) { if (cat == BudgetCategory.MDA) return "MDA"; if (cat == BudgetCategory.AudioVideo) return "AudioVideo"; if (cat == BudgetCategory.SDA) return "SDA"; if (cat == BudgetCategory.Tele) return "Tele"; if (cat == BudgetCategory.Data) return "Data"; if (cat == BudgetCategory.Cross) return "Cross"; if (cat == BudgetCategory.Kasse) return "Kasse"; if (cat == BudgetCategory.Aftersales) return "Aftersales"; if (cat == BudgetCategory.MDASDA) return "MDASDA"; if (cat == BudgetCategory.Butikk) return "Butikk"; if (cat == BudgetCategory.Daglig) return "Daglig"; if (cat == BudgetCategory.AlleSelgere) return "AlleSelgere"; return ""; }
public bool BuildPage(BudgetCategory cat, string strHash, string htmlPage, DateTime date) { pickedDate = date; string katArg = BudgetCategoryClass.TypeToName(cat); bool abort = main.HarSisteVersjonBudget(cat, strHash); try { if (!runningInBackground && !abort) main.timewatch.Start(); if (!runningInBackground) main.appConfig.savedBudgetPage = BudgetCategoryClass.TypeToName(cat); if (!abort) { Log.n("Oppdaterer [" + BudgetCategoryClass.TypeToName(cat) + "].."); OpenPage_Loading(); doc = new List<string>(); main.openXml.DeleteDocument(BudgetCategoryClass.TypeToName(cat), pickedDate); AddPage_Start(true, "Budsjett (" + BudgetCategoryClass.TypeToName(cat) + ")"); AddPage_Title("Budsjett (" + main.avdeling.Get(main.appConfig.Avdeling) + ")"); ShowProgress(); BudgetImporter importer = new BudgetImporter(main, DateTime.Now); if (main.tableMacroQuick == null) { Log.n("Fant ikke data fra Makro, forsøker å hente CSV..", null, true); main.tableMacroQuick = importer.ImportElguideBudget(main.appConfig.Avdeling); } if (main.appConfig.dailyBudgetIncludeInQuickRanking) MakeDailyBudgetFromDatabase(); DailyBudgetMacroInfo budgetInfo = null; if (main.appConfig.macroImportQuickSales) budgetInfo = importer.ImportElguideServices(); MakeDailyBudgetFromElguide(budgetInfo); AddPage_End(); if (FormMain.stopRanking) { main.ClearHash(katArg); Log.n("Lasting avbrutt", Color.Red); OpenPage_Stopped(); FormMain.stopRanking = false; } else { File.WriteAllLines(htmlPage, doc.ToArray(), Encoding.Unicode); OpenPage(htmlPage); if (!runningInBackground) Log.n("Side [" + katArg + "] tok " + main.timewatch.Stop() + " sekunder.", Color.Black, true); return true; } } else OpenPage(htmlPage); } catch (Exception ex) { Log.Unhandled(ex); if (!runningInBackground) { OpenPage_Error(); FormError errorMsg = new FormError("Feil ved generering av side for [" + katArg + "]", ex); errorMsg.ShowDialog(); } } return false; }
private void BuildBudget(BudgetCategory cat, string currentHash, string htmlPage, bool bg = false) { string katArg = BudgetCategoryClass.TypeToName(cat); bool abort = HarSisteVersjonBudget(cat, currentHash); try { if (!bg && !abort) timewatch.Start(); if (!bg) appConfig.savedBudgetPage = BudgetCategoryClass.TypeToName(cat); if (!abort) { Log.n("Oppdaterer [" + katArg + " Budget].."); if (!bg) webBudget.Navigate(htmlLoading); var doc = new List<string>(); DateTime dtPick = pickerBudget.Value; DateTime dtFra = GetFirstDayOfMonth(dtPick); DateTime dtTil = dtPick; if (datoPeriodeVelger && !bg) { dtFra = datoPeriodeFra; dtTil = datoPeriodeTil; } var ranking = new RankingBudget(this, dtFra, dtTil, cat); if (ranking.budgetInfo == null) { ClearBudgetHash(cat); Log.n("Mangler budsjett for " + katArg + "."); doc = new List<string>(); doc.Add(File.ReadAllText(htmlSetupBudget)); File.WriteAllLines(htmlPage, doc.ToArray(), Encoding.Unicode); if (!bg) webBudget.Navigate(htmlPage); return; } GetHtmlStart(doc, true, "Ranking: Budsjett"); doc.Add("<h1>Budsjett avdeling: " + katArg + " (" + avdeling.Get(appConfig.Avdeling) + ")</h1>"); doc.Add("<table style='width:100%;display:none;' class='hidePdf'><tr><td>Hopp til: "); if (ranking.budgetInfo.acc > 0) doc.Add("<span class=\"link_button\"><a href='#Tilbehør'>Tilbehør</a></span> "); if (ranking.budgetInfo.finans > 0) doc.Add("<span class=\"link_button\"><a href='#Finansiering'>Finansiering</a></span> "); if (ranking.budgetInfo.rtgsa > 0) if (cat != BudgetCategory.MDA && cat != BudgetCategory.SDA) doc.Add("<span class=\"link_button\"><a href='#RTG/SA'>RTG/SA</a></span> "); if (ranking.budgetInfo.strom > 0) doc.Add("<span class=\"link_button\"><a href='#Norges Energi'>Strøm</a></span> "); if (ranking.budgetInfo.ta > 0) doc.Add("<span class=\"link_button\"><a href='#Trygghetsavtale'>Trygghetsavtale</a></span> "); if (ranking.budgetInfo.vinn > 0) doc.Add("<span class=\"link_button\"><a href='#Vinnprodukt'>Vinnprodukter</a></span> "); doc.Add("</td></tr></table>"); if (ranking.budgetInfo.inntjening > 0) doc.AddRange(ranking.GetTableHtml(cat)); if (ranking.budgetInfo.acc > 0) doc.AddRange(ranking.GetTableHtmlProduct(cat, BudgetType.Acc)); if (ranking.budgetInfo.finans > 0) doc.AddRange(ranking.GetTableHtmlProduct(cat, BudgetType.Finans)); if (ranking.budgetInfo.rtgsa > 0) if (cat != BudgetCategory.MDA && cat != BudgetCategory.SDA) doc.AddRange(ranking.GetTableHtmlProduct(cat, BudgetType.Rtgsa)); if (ranking.budgetInfo.strom > 0) doc.AddRange(ranking.GetTableHtmlProduct(cat, BudgetType.Strom)); if (ranking.budgetInfo.ta > 0) doc.AddRange(ranking.GetTableHtmlProduct(cat, BudgetType.TA)); if (ranking.budgetInfo.vinn > 0) doc.AddRange(ranking.GetTableHtmlProduct(cat, BudgetType.Vinnprodukt)); doc.Add(Resources.htmlEnd); if (stopRanking) { stopRanking = false; ClearBudgetHash(cat); Log.n("Ranking stoppet.", Color.Red); webBudget.Navigate(htmlStopped); } else { if (datoPeriodeVelger && !bg) { File.WriteAllLines(htmlPeriode, doc.ToArray(), Encoding.Unicode); webBudget.Navigate(htmlPeriode); } else { File.WriteAllLines(htmlPage, doc.ToArray(), Encoding.Unicode); if (!bg) webBudget.Navigate(htmlPage); if (!bg) Log.n("Budsjett [" + katArg + " Budget] tok " + timewatch.Stop() + " sekunder.", Color.Black, true); } } } else if (!bg) webBudget.Navigate(htmlPage); } catch (Exception ex) { Log.Unhandled(ex); if (!bg) { webBudget.Navigate(htmlError); FormError errorMsg = new FormError("Feil ved generering av budsjett for [" + katArg + " Budget]", ex); errorMsg.ShowDialog(this); } } }
public bool HarSisteVersjonBudget(BudgetCategory cat, string oldHash) { try { if (datoPeriodeVelger) return false; string html = ""; if (cat == BudgetCategory.MDA) html = htmlBudgetMda; else if (cat == BudgetCategory.AudioVideo) html = htmlBudgetAudioVideo; else if (cat == BudgetCategory.SDA) html = htmlBudgetSda; else if (cat == BudgetCategory.Tele) html = htmlBudgetTele; else if (cat == BudgetCategory.Data) html = htmlBudgetData; else if (cat == BudgetCategory.Cross) html = htmlBudgetCross; else if (cat == BudgetCategory.Kasse) html = htmlBudgetKasse; else if (cat == BudgetCategory.Aftersales) html = htmlBudgetAftersales; else if (cat == BudgetCategory.Daglig) html = htmlBudgetDaily; else return false; if (File.Exists(html)) { string newHash = appConfig.Avdeling + pickerBudget.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString(); if (newHash == oldHash) { buttonBudgetUpdate.BackColor = SystemColors.ControlLight; buttonBudgetUpdate.ForeColor = SystemColors.ControlText; Log.d("[" + BudgetCategoryClass.TypeToName(cat) + "]: bruker mellomlagret kopi!"); return true; } else { buttonBudgetUpdate.BackColor = SystemColors.ControlLight; buttonBudgetUpdate.ForeColor = SystemColors.ControlText; Log.d("[" + BudgetCategoryClass.TypeToName(cat) + "]: Genererer ny ranking.."); return false; } } } catch (Exception ex) { Log.Unhandled(ex); return false; } return false; }
public RankingBudget(FormMain form, DateTime dtFraArg, DateTime dtTilArg, BudgetCategory cat) { try { this.main = form; dtFra = dtFraArg; dtTil = dtTilArg; velgerPeriode = FormMain.datoPeriodeVelger; this.varekoderAlle = main.appConfig.varekoder.ToList(); this.varekoderAlleAlias = varekoderAlle.Where(item => item.synlig == true).Select(x => x.alias).Distinct(); budget = new BudgetObj(main); budgetInfo = budget.GetBudgetInfo(dtTil, cat); if (budgetInfo != null) if (budgetInfo.selgere != null) if (budgetInfo.selgere.Count == 0) budgetInfo = null; } catch (Exception ex) { Log.Unhandled(ex); budgetInfo = null; } }
private DataTable MakeTableBudgetProduct(BudgetCategory cat, BudgetType product, BudgetValueType type) { try { DataTable dtWork = ReadyTableProductNew(); sqlce = main.database.CallMonthTable(dtTil, main.appConfig.Avdeling); if (sqlce.Rows.Count == 0) return dtWork; string strSel = ""; DataRow[] rowsSel; for (int i = 0; i < budgetInfo.selgere.Count; i++) strSel += " OR Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"; strSel = strSel.Substring(4, strSel.Length - 4); rowsSel = sqlce.Select(strSel + " AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')"); DataTable dtSel = rowsSel.Any() ? rowsSel.CopyToDataTable() : sqlce.Clone(); object r; decimal omset_total = 0, inntjen_total = 0, omsetExMva_total = 0; int d = 0; if (cat == BudgetCategory.MDA) d = 1; else if (cat == BudgetCategory.AudioVideo) d = 2; else if (cat == BudgetCategory.SDA) d = 3; else if (cat == BudgetCategory.Tele) d = 4; else if (cat == BudgetCategory.Data) d = 5; decimal target_value = 0; if (product == BudgetType.Acc) target_value = budgetInfo.acc; else if (product == BudgetType.Finans) target_value = budgetInfo.finans; else if (product == BudgetType.Rtgsa) target_value = budgetInfo.rtgsa; else if (product == BudgetType.Strom) target_value = budgetInfo.strom; else if (product == BudgetType.TA) target_value = budgetInfo.ta; else if (product == BudgetType.Vinnprodukt) target_value = budgetInfo.vinn; inntjen_total = Compute(dtSel, "Sum(Btokr)"); omset_total = Compute(dtSel, "Sum(Salgspris)"); omsetExMva_total = Compute(dtSel, "Sum(SalgsprisExMva)"); DataRow dtRowAvd = dtWork.NewRow(); dtRowAvd["Kategori"] = product; dtRowAvd["Selgerkode"] = "Totalt"; dtRowAvd["Actual_inntjen"] = inntjen_total; dtRowAvd["Actual_omset"] = omset_total; dtRowAvd["Actual_omsetExMva"] = omsetExMva_total; if (omsetExMva_total != 0) dtRowAvd["Actual_margin"] = Math.Round(inntjen_total / omsetExMva_total, 2); else dtRowAvd["Actual_margin"] = 0; if (sqlce.Rows.Count > 0) { decimal inntjen_prod = 0, antall_prod = 0, omset_prod = 0, hovedprod_antall = 0, vinnprodukt_poeng = 0; KgsaBudgetProduct Actual = new KgsaBudgetProduct(product, type); KgsaBudgetField actual_1 = new KgsaBudgetField(); KgsaBudgetField actual_2 = new KgsaBudgetField(); KgsaBudgetField actual_3 = new KgsaBudgetField(); KgsaBudgetProduct Target = new KgsaBudgetProduct(product, type); KgsaBudgetField target_1 = new KgsaBudgetField(); KgsaBudgetField target_2 = new KgsaBudgetField(); KgsaBudgetProduct Difference = new KgsaBudgetProduct(product, type); KgsaBudgetField difference_1 = new KgsaBudgetField(); KgsaBudgetField difference_2 = new KgsaBudgetField(); if (product == BudgetType.Vinnprodukt) { decimal antall = 0; List<VinnproduktItem> items = main.vinnprodukt.GetList(); foreach (VinnproduktItem item in items) { inntjen_prod += Compute(dtSel, "Sum(Btokr)", "[Varekode] = '" + item.varekode + "'"); omset_prod += Compute(dtSel, "Sum(Salgspris)", "[Varekode] = '" + item.varekode + "'"); antall = Compute(dtSel, "Sum(Antall)", "[Varekode] = '" + item.varekode + "'"); antall_prod += antall; vinnprodukt_poeng += item.poeng * antall; } } else if (product == BudgetType.Acc) { int[] accessoriesGrpList = main.appConfig.GetAccessorieGroups(0); foreach (int ac in accessoriesGrpList) { inntjen_prod += Compute(dtSel, "Sum(Btokr)", "[Varegruppe] = " + ac); omset_prod += Compute(dtSel, "Sum(Salgspris)", "[Varegruppe] = " + ac); antall_prod += Compute(dtSel, "Sum(Antall)", "[Varegruppe] = " + ac); } } else if (product == BudgetType.Finans) { var rowf = dtSel.Select("[Varegruppe] = 961"); for (int f = 0; f < rowf.Length; f++) { var rows2 = sqlce.Select("[Bilagsnr] = " + rowf[f]["Bilagsnr"]); DataTable dtFinans = rows2.Any() ? rows2.CopyToDataTable() : sqlce.Clone(); dtFinans.DefaultView.Sort = "Salgspris DESC"; int gruppe = Convert.ToInt32(dtFinans.Rows[0]["Varegruppe"].ToString().Substring(0, 1)); if (gruppe == d || d == 0) { r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = 961 AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString()); if (!DBNull.Value.Equals(r)) inntjen_prod += Convert.ToDecimal(r); r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = 961 AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString()); if (!DBNull.Value.Equals(r)) antall_prod += Convert.ToInt32(r); } } } else if (product == BudgetType.Rtgsa) { r = dtSel.Compute("Sum(Antall)", "([Varegruppe]=531 OR [Varegruppe]=533 OR [Varegruppe]=534 OR [Varegruppe]=224 OR [Varegruppe]=431)"); if (!DBNull.Value.Equals(r)) hovedprod_antall = Convert.ToInt32(r); foreach (var varekode in varekoderAlle) { r = dtSel.Compute("Sum(Btokr)", "[Varekode]='" + varekode.kode + "'"); if (!DBNull.Value.Equals(r)) inntjen_prod += Convert.ToDecimal(r); r = dtSel.Compute("Sum(Salgspris)", "[Varekode]='" + varekode.kode + "'"); if (!DBNull.Value.Equals(r)) omset_prod += Convert.ToDecimal(r); if (varekode.synlig) { r = dtSel.Compute("Sum(Antall)", "[Varekode]='" + varekode.kode + "'"); if (!DBNull.Value.Equals(r)) antall_prod += Convert.ToInt32(r); } } } else if (product == BudgetType.Strom) { r = dtSel.Compute("Sum(Btokr)", "[Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*'"); if (!DBNull.Value.Equals(r)) inntjen_prod = Convert.ToDecimal(r); r = dtSel.Compute("Sum(Salgspris)", "[Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*'"); if (!DBNull.Value.Equals(r)) omset_prod = Convert.ToDecimal(r); r = dtSel.Compute("Sum(Antall)", "[Varekode] LIKE 'ELSTROM*'"); if (!DBNull.Value.Equals(r)) antall_prod = Convert.ToInt32(r); } else if (product == BudgetType.TA) { r = dtSel.Compute("Sum(Btokr)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'"); if (!DBNull.Value.Equals(r)) inntjen_prod = Convert.ToDecimal(r); r = dtSel.Compute("Sum(Salgspris)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'"); if (!DBNull.Value.Equals(r)) omset_prod = Convert.ToDecimal(r); r = dtSel.Compute("Sum(Antall)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'"); if (!DBNull.Value.Equals(r)) antall_prod = Convert.ToInt32(r); } if (type == BudgetValueType.Poeng) { actual_1.value = vinnprodukt_poeng; actual_1.type = BudgetValueType.Poeng; actual_2.value = antall_prod; actual_2.type = BudgetValueType.Antall; actual_3.value = inntjen_prod; actual_3.type = BudgetValueType.Inntjening; target_1.value = target_value * budgetInfo.timeElapsedCoefficient; target_1.type = BudgetValueType.Poeng; target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed; target_2.type = BudgetValueType.AntallPerDag; difference_1.value = actual_1.value - target_1.value; difference_1.type = BudgetValueType.Poeng; difference_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value; difference_2.type = BudgetValueType.AntallPerDag; } else if (type == BudgetValueType.Hitrate) { if (hovedprod_antall != 0) actual_1.value = antall_prod / hovedprod_antall; else actual_1.value = 0; actual_1.type = BudgetValueType.Hitrate; actual_2.value = antall_prod; actual_2.type = BudgetValueType.Antall; actual_3.value = inntjen_prod; actual_3.type = BudgetValueType.Inntjening; target_1.value = target_value; target_1.type = BudgetValueType.Hitrate; target_2.value = (hovedprod_antall * target_value) / budgetInfo.daysElapsed; target_2.type = BudgetValueType.AntallPerDag; difference_1.value = actual_1.value - target_1.value; difference_1.type = BudgetValueType.Hitrate; difference_2.value = ((hovedprod_antall * actual_1.value) / budgetInfo.daysElapsed) - target_2.value; difference_2.type = BudgetValueType.AntallPerDag; } else if (type == BudgetValueType.Antall) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = inntjen_prod; actual_2.type = BudgetValueType.Inntjening; if (inntjen_total != 0) actual_3.value = inntjen_prod / inntjen_total; else actual_3.value = 0; actual_3.type = BudgetValueType.SoM; target_1.value = target_value * budgetInfo.timeElapsedCoefficient; target_1.type = BudgetValueType.Antall; target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed; target_2.type = BudgetValueType.AntallPerDag; difference_1.value = actual_1.value - target_1.value; difference_1.type = BudgetValueType.Antall; difference_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value; difference_2.type = BudgetValueType.AntallPerDag; } if (type == BudgetValueType.Inntjening) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = inntjen_prod; actual_2.type = BudgetValueType.Inntjening; if (inntjen_total != 0) actual_3.value = inntjen_prod / inntjen_total; else actual_3.value = 0; actual_3.type = BudgetValueType.SoM; target_1.value = target_value * budgetInfo.timeElapsedCoefficient; target_1.type = BudgetValueType.Inntjening; target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed; target_2.type = BudgetValueType.InntjeningPerDag; difference_1.value = actual_2.value - target_1.value; difference_1.type = BudgetValueType.Inntjening; difference_2.value = (inntjen_prod / budgetInfo.daysElapsed) - target_2.value; difference_2.type = BudgetValueType.InntjeningPerDag; } if (type == BudgetValueType.Omsetning) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = omset_prod; actual_2.type = BudgetValueType.Omsetning; if (omset_prod != 0) actual_3.value = omset_total / omset_prod; else actual_3.value = 0; actual_3.type = BudgetValueType.SoB; target_1.value = target_value * budgetInfo.timeElapsedCoefficient; target_1.type = BudgetValueType.Omsetning; target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed; target_2.type = BudgetValueType.OmsetningPerDag; difference_1.value = actual_2.value - target_1.value; difference_1.type = BudgetValueType.Omsetning; difference_2.value = (omset_prod / budgetInfo.daysElapsed) - target_2.value; difference_2.type = BudgetValueType.OmsetningPerDag; } if (type == BudgetValueType.SoB) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = omset_prod; actual_2.type = BudgetValueType.Omsetning; if (omset_total != 0) actual_3.value = omset_prod / omset_total; else actual_3.value = 0; actual_3.type = BudgetValueType.SoB; target_1.value = target_value; target_1.type = BudgetValueType.SoB; target_2.value = omset_total * target_value; target_2.type = BudgetValueType.Omsetning; difference_1.value = actual_3.value - target_1.value; difference_1.type = BudgetValueType.SoB; difference_2.value = actual_2.value - target_2.value; difference_2.type = BudgetValueType.Omsetning; } if (type == BudgetValueType.SoM) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = inntjen_prod; actual_2.type = BudgetValueType.Inntjening; if (inntjen_total != 0) actual_3.value = inntjen_prod / inntjen_total; else actual_3.value = 0; actual_3.type = BudgetValueType.SoM; target_1.value = target_value; target_1.type = BudgetValueType.SoM; target_2.value = target_1.value * inntjen_total; target_2.type = BudgetValueType.Inntjening; difference_1.value = actual_3.value - target_1.value; difference_1.type = BudgetValueType.SoM; difference_2.value = actual_2.value - target_2.value; difference_2.type = BudgetValueType.Inntjening; } Actual.fields.Add(actual_1); // kolonne 1 av 3 Actual.fields.Add(actual_2); // kolonne 2 av 3 Actual.fields.Add(actual_3); // kolonne 3 av 3 Target.fields.Add(target_1); // kolonne 1 av 3 Target.fields.Add(target_2); // kolonne 2 av 3 Difference.fields.Add(difference_1); // kolonne 1 av 3 Difference.fields.Add(difference_2); // kolonne 2 av 3 dtRowAvd["Field1"] = PrepFields(Actual, false, true); dtRowAvd["Field2"] = PrepFields(Target); dtRowAvd["Field3"] = PrepFields(Difference, true); dtRowAvd["Sort_value"] = -9999999; } budgetInfo.chartdata = new List<BudgetChartData>() { }; for (int i = 0; i < budgetInfo.selgere.Count; i++) { decimal omset_sel = 0, inntjen_sel = 0, omsetExMva_sel = 0; inntjen_sel = Compute(sqlce, "Sum(Btokr)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); omset_sel = Compute(sqlce, "Sum(Salgspris)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); omsetExMva_sel = Compute(sqlce, "Sum(SalgsprisExMva)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); DataRow dtRowSel = dtWork.NewRow(); dtRowSel["Kategori"] = product; dtRowSel["Selgerkode"] = budgetInfo.selgere[i].selgerkode; dtRowSel["Actual_inntjen"] = inntjen_sel; dtRowSel["Actual_omset"] = omset_sel; dtRowSel["Actual_omsetExMva"] = omsetExMva_sel; if (omsetExMva_sel != 0) dtRowSel["Actual_margin"] = Math.Round(inntjen_sel / omsetExMva_sel, 2); else dtRowSel["Actual_margin"] = 0; if (sqlce.Rows.Count > 0) { decimal inntjen_prod = 0, antall_prod = 0, omset_prod = 0, hovedprod_antall = 0, vinnprodukt_poeng = 0; KgsaBudgetProduct Actual = new KgsaBudgetProduct(product, type); KgsaBudgetField actual_1 = new KgsaBudgetField(); KgsaBudgetField actual_2 = new KgsaBudgetField(); KgsaBudgetField actual_3 = new KgsaBudgetField(); KgsaBudgetProduct Target = new KgsaBudgetProduct(product, type); KgsaBudgetField target_1 = new KgsaBudgetField(); KgsaBudgetField target_2 = new KgsaBudgetField(); KgsaBudgetProduct Difference = new KgsaBudgetProduct(product, type); KgsaBudgetField diff_1 = new KgsaBudgetField(); KgsaBudgetField diff_2 = new KgsaBudgetField(); if (product == BudgetType.Vinnprodukt) { decimal antall = 0; List<VinnproduktItem> items = main.vinnprodukt.GetList(); foreach (VinnproduktItem item in items) { inntjen_prod += Compute(sqlce, "Sum(Btokr)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); omset_prod += Compute(sqlce, "Sum(Salgspris)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); antall = Compute(sqlce, "Sum(Antall)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); antall_prod += antall; vinnprodukt_poeng += item.poeng * antall; } } else if (product == BudgetType.Acc) { int[] accessoriesGrpList = main.appConfig.GetAccessorieGroups(0); foreach (int ac in accessoriesGrpList) { r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) antall_prod += Convert.ToInt32(r); r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) inntjen_prod += Convert.ToDecimal(r); r = sqlce.Compute("Sum(Salgspris)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) omset_prod += Convert.ToDecimal(r); } } else if (product == BudgetType.Finans) { var rowf = sqlce.Select("[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "'"); for (int f = 0; f < rowf.Length; f++) { var rows2 = sqlce.Select("[Bilagsnr] = " + rowf[f]["Bilagsnr"]); DataTable dtFinans = rows2.Any() ? rows2.CopyToDataTable() : sqlce.Clone(); dtFinans.DefaultView.Sort = "Salgspris DESC"; int gruppe = Convert.ToInt32(dtFinans.Rows[0]["Varegruppe"].ToString().Substring(0, 1)); if (gruppe == d || d == 0) { r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "' AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString()); if (!DBNull.Value.Equals(r)) inntjen_prod += Convert.ToDecimal(r); r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "' AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString()); if (!DBNull.Value.Equals(r)) antall_prod += Convert.ToInt32(r); } } } else if (product == BudgetType.Rtgsa) { r = sqlce.Compute("Sum(Antall)", "([Varegruppe]=531 OR [Varegruppe]=533 OR [Varegruppe]=534 OR [Varegruppe]=224 OR [Varegruppe]=431) AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) hovedprod_antall = Convert.ToInt32(r); foreach (var varekode in varekoderAlle) { r = sqlce.Compute("Sum(Salgspris)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) omset_prod += Convert.ToDecimal(r); r = sqlce.Compute("Sum(Btokr)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) inntjen_prod += Convert.ToDecimal(r); if (varekode.synlig) { r = sqlce.Compute("Sum(Antall)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) antall_prod += Convert.ToInt32(r); } } } else if (product == BudgetType.Strom) { r = sqlce.Compute("Sum(Btokr)", "([Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*') AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) inntjen_prod = Convert.ToDecimal(r); r = sqlce.Compute("Sum(Salgspris)", "([Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*') AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) omset_prod = Convert.ToDecimal(r); r = sqlce.Compute("Sum(Antall)", "[Varekode] LIKE 'ELSTROM*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) antall_prod = Convert.ToInt32(r); } else if (product == BudgetType.TA) { r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) inntjen_prod = Convert.ToDecimal(r); r = sqlce.Compute("Sum(Salgspris)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) omset_prod = Convert.ToDecimal(r); r = sqlce.Compute("Sum(Antall)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'"); if (!DBNull.Value.Equals(r)) antall_prod = Convert.ToInt32(r); } if (type == BudgetValueType.Poeng) { actual_1.value = vinnprodukt_poeng; actual_1.type = BudgetValueType.Poeng; actual_2.value = antall_prod; actual_2.type = BudgetValueType.Antall; actual_3.value = inntjen_prod; actual_3.type = BudgetValueType.Inntjening; target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight; target_1.type = BudgetValueType.Poeng; target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight; target_2.type = BudgetValueType.AntallPerDag; diff_1.value = actual_1.value - target_1.value; diff_1.type = BudgetValueType.Poeng; diff_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value; diff_2.type = BudgetValueType.AntallPerDag; } else if (type == BudgetValueType.Hitrate) { if (hovedprod_antall != 0) actual_1.value = antall_prod / hovedprod_antall; else actual_1.value = 0; actual_1.type = BudgetValueType.Hitrate; actual_2.value = antall_prod; actual_2.type = BudgetValueType.Antall; actual_3.value = inntjen_prod; actual_3.type = BudgetValueType.Inntjening; target_1.value = target_value; target_1.type = BudgetValueType.Hitrate; target_2.value = (hovedprod_antall * target_value) / budgetInfo.daysElapsed; target_2.type = BudgetValueType.AntallPerDag; diff_1.value = actual_1.value - target_1.value; diff_1.type = BudgetValueType.Hitrate; diff_2.value = ((hovedprod_antall * actual_1.value) / budgetInfo.daysElapsed) - target_2.value; diff_2.type = BudgetValueType.AntallPerDag; } else if (type == BudgetValueType.Antall) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = inntjen_prod; actual_2.type = BudgetValueType.Inntjening; if (inntjen_sel != 0) actual_3.value = inntjen_prod / inntjen_sel; else actual_3.value = 0; actual_3.type = BudgetValueType.SoM; target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight; target_1.type = BudgetValueType.Antall; target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight; target_2.type = BudgetValueType.AntallPerDag; diff_1.value = actual_1.value - target_1.value; diff_1.type = BudgetValueType.Antall; diff_2.value = antall_prod / budgetInfo.daysElapsed - target_2.value; diff_2.type = BudgetValueType.AntallPerDag; } else if (type == BudgetValueType.Inntjening) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = inntjen_prod; actual_2.type = BudgetValueType.Inntjening; if (inntjen_sel != 0) actual_3.value = inntjen_prod / inntjen_sel; else actual_3.value = 0; actual_3.type = BudgetValueType.SoM; target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight; target_1.type = BudgetValueType.Inntjening; target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight; target_2.type = BudgetValueType.InntjeningPerDag; diff_1.value = actual_2.value - target_1.value; diff_1.type = BudgetValueType.Inntjening; diff_2.value = inntjen_prod / budgetInfo.daysElapsed - target_2.value; diff_2.type = BudgetValueType.InntjeningPerDag; } else if (type == BudgetValueType.Omsetning) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = omset_prod; actual_2.type = BudgetValueType.Omsetning; if (omset_sel != 0) actual_3.value = omset_prod / omset_sel; else actual_3.value = 0; actual_3.type = BudgetValueType.SoB; target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight; target_1.type = BudgetValueType.Omsetning; target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight; target_2.type = BudgetValueType.OmsetningPerDag; diff_1.value = actual_2.value - target_1.value; diff_1.type = BudgetValueType.Omsetning; diff_2.value = omset_prod / budgetInfo.daysElapsed - target_2.value; diff_2.type = BudgetValueType.OmsetningPerDag; } else if (type == BudgetValueType.SoB) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = omset_prod; actual_2.type = BudgetValueType.Omsetning; if (omset_sel != 0) actual_3.value = omset_prod / omset_sel; else actual_3.value = 0; actual_3.type = BudgetValueType.SoB; target_1.value = target_value; target_1.type = BudgetValueType.SoB; target_2.value = omset_sel * target_value; target_2.type = BudgetValueType.Omsetning; diff_1.value = actual_3.value - target_1.value; diff_1.type = BudgetValueType.SoB; diff_2.value = actual_2.value - target_2.value; diff_2.type = BudgetValueType.Omsetning; } else if (type == BudgetValueType.SoM) { actual_1.value = antall_prod; actual_1.type = BudgetValueType.Antall; actual_2.value = inntjen_prod; actual_2.type = BudgetValueType.Inntjening; if (inntjen_sel != 0) actual_3.value = inntjen_prod / inntjen_sel; else actual_3.value = 0; actual_3.type = BudgetValueType.SoM; target_1.value = target_value; target_1.type = BudgetValueType.SoM; target_2.value = inntjen_sel * target_value; target_2.type = BudgetValueType.Inntjening; diff_1.value = actual_3.value - target_1.value; diff_1.type = BudgetValueType.SoM; diff_2.value = actual_2.value - target_2.value; diff_2.type = BudgetValueType.Inntjening; } Actual.fields.Add(actual_1); // kolonne 1 av 3 Actual.fields.Add(actual_2); // kolonne 2 av 3 Actual.fields.Add(actual_3); // kolonne 3 av 3 Target.fields.Add(target_1); // kolonne 1 av 2 Target.fields.Add(target_2); // kolonne 2 av 2 Difference.fields.Add(diff_1); // kolonne 1 av 2 Difference.fields.Add(diff_2); // kolonne 2 av 2 dtRowSel["Field1"] = PrepFields(Actual, false, true); dtRowSel["Field2"] = PrepFields(Target); dtRowSel["Field3"] = PrepFields(Difference, true); if (type == BudgetValueType.Antall || type == BudgetValueType.Poeng) { dtRowSel["Sort_value"] = actual_1.value; budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_1.value)); } else if (type == BudgetValueType.Inntjening || type == BudgetValueType.Omsetning) { dtRowSel["Sort_value"] = actual_2.value; budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_2.value)); } else if (type == BudgetValueType.SoM || type == BudgetValueType.SoB) { dtRowSel["Sort_value"] = actual_3.value; budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_3.value)); } else if (type == BudgetValueType.Hitrate) { dtRowSel["Sort_value"] = actual_1.value; budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_1.value)); } } dtWork.Rows.Add(dtRowSel); } dtWork.Rows.Add(dtRowAvd); DataView dv = dtWork.DefaultView; dv.Sort = "Sort_value desc"; budgetInfo.chartdata = budgetInfo.chartdata.OrderByDescending(x => x.actual).ToList(); return dv.ToTable(); } catch (Exception ex) { Log.Unhandled(ex); return null; } }