/// <summary> /// /// </summary> /// <returns></returns> public BudgetStatusContract GetBudgetStatus() { BudgetStatusContract budgetStatus = new BudgetStatusContract(); var query = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (query == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = budgetStatus.BudgetAvailable = 0; budgStatu.BudgetAllocated = budgetStatus.BudgetAllocated = 0; budgStatu.BudgetRequired = budgetStatus.BudgetRequired = 00; budgStatu.DateUpdated = DateTime.Now; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); orgMaintEntitiesContext.SaveChanges(); } else { budgetStatus.BudgetAvailable = query.BudgetAvailable; budgetStatus.BudgetAllocated = query.BudgetAllocated; budgetStatus.BudgetRequired = query.BudgetRequired; budgetStatus.DateUpdated = query.DateUpdated; budgetStatus.DateUpdatedString = query.DateUpdated.ToShortDateString(); } return budgetStatus; }
void updateBudgetStatus(decimal budgetRequired = 0, decimal budgetAvailable = 0) { var query = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (query == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = 0; budgStatu.BudgetAllocated = 0; budgStatu.BudgetRequired = budgetRequired; budgStatu.DateUpdated = DateTime.Now; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); } else { query.BudgetRequired += budgetRequired; query.DateUpdated = DateTime.Now; } orgMaintEntitiesContext.SaveChanges(); }
// corerect one public bool AllocateFunds2(AllocateWrapper fundsForAllocationBox) { EntitySummaryContract updatedEntityStatus = new EntitySummaryContract(); var queryBudgetStatus = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (queryBudgetStatus == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = 0; budgStatu.BudgetAllocated = 0; budgStatu.DateUpdated = DateTime.Now; var queryentity = (from entityRequired in orgMaintEntitiesContext.EntityFinanceSummaries select entityRequired.BudgetRequired).Sum(); budgStatu.BudgetRequired = (decimal)queryentity; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); } else { decimal totalFundAllocated = 0M; var queryentities = (from entityRequired in orgMaintEntitiesContext.EntityFinanceSummaries where entityRequired.BudgetRequired > 0 orderby entityRequired.Priority, entityRequired.BudgetRequired descending select entityRequired); int entitiesAllocated = 0; queryentities.ToList().ForEach(rec => { if (queryBudgetStatus.BudgetAvailable > 0) { decimal fundAllocated = rec.BudgetRequired; if (fundAllocated >= queryBudgetStatus.BudgetAvailable) { fundAllocated = queryBudgetStatus.BudgetAvailable; // queryBudgetStatus.BudgetAvailable = 0; } totalFundAllocated += fundAllocated; rec.BudgetRequired -= fundAllocated; rec.BudgetAllocated += fundAllocated; queryBudgetStatus.BudgetAvailable -= fundAllocated; queryBudgetStatus.BudgetAllocated += fundAllocated; queryBudgetStatus.BudgetRequired -= fundAllocated; entitiesAllocated++; BudgetHistory newBudgetHistoryRecord = new BudgetHistory { Amount = totalFundAllocated, DebitCredit = "Debit", Date = (DateTime)DateTime.Now, Principal = rec.EntityName, Comments = string.Format("Priority {0},index {0}", rec.Priority, entitiesAllocated) }; orgMaintEntitiesContext.BudgetHistories.Add(newBudgetHistoryRecord); } }); //if (totalFundAllocated > 0) //{ // BudgetHistory newBudgetHistoryRecord = new BudgetHistory // { // Amount = totalFundAllocated, // DebitCredit = "Debit", // Date = (DateTime)DateTime.Now, // Comments = string.Format("Number Allocated={0}") // }; // orgMaintEntitiesContext.BudgetHistories.Add(newBudgetHistoryRecord); //} orgMaintEntitiesContext.SaveChanges(); } updateEntityStatus(); return true; }
public bool updateEntityStatus() { EntitySummaryContract entityStatus = new EntitySummaryContract(); var query = (from entitySummary in orgMaintEntitiesContext.EntitySummaries select entitySummary).FirstOrDefault(); if (query == null) { EntitySummary newEntitySummary = new EntitySummary(); entityStatus.TotalEntities = newEntitySummary.TotalEntities = 0; entityStatus.TotalEntitiesAllocable = newEntitySummary.TotalEntitiesAllocable = 00; entityStatus.TotalEntitiesUnallocated = newEntitySummary.TotalEntitiesUnallocated = 00; entityStatus.DateUpdated = newEntitySummary.DateUpdated = DateTime.Now; entityStatus.DateUpdatedString = newEntitySummary.DateUpdated.ToShortDateString(); orgMaintEntitiesContext.EntitySummaries.Add(newEntitySummary); orgMaintEntitiesContext.SaveChanges(); query = newEntitySummary; } query.TotalEntities = 0; query.TotalEntitiesAllocable = 00; query.TotalEntitiesAllocated = 0; query.TotalEntitiesUnallocated = 00; query.DateUpdated = DateTime.Now; List<EntityFinanceSummaryContract> entityList = GetEntitySummaryList(); decimal budgetAvailable = 0; var query2 = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (query2 == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = 0; budgStatu.BudgetAllocated = 0; budgStatu.BudgetRequired = 00; budgStatu.DateUpdated = DateTime.Now; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); } else budgetAvailable = query2.BudgetAvailable; foreach (EntityFinanceSummaryContract entityElement in entityList) { query.TotalEntities += 1; if (entityElement.BudgetAllocated > 0) query.TotalEntitiesAllocated += 1; else if (budgetAvailable > 0) query.TotalEntitiesAllocable += 1; budgetAvailable -= entityElement.BudgetRequired; } if (budgetAvailable < 0) { query2.BudgetRequired = -1 * budgetAvailable; } query.TotalEntitiesUnallocated = query.TotalEntities - (query.TotalEntitiesAllocable + query.TotalEntitiesAllocated); orgMaintEntitiesContext.SaveChanges(); return true; }
public bool AddContributor(Contributor contributor) { List<ContributorContract> updatedContributorList = new List<ContributorContract>(); Contributor newContributorRecord = new Contributor { ContributorID = contributor.ContributorID, OriginalCurrencyAmount = contributor.OriginalCurrencyAmount, ContributorName = contributor.ContributorName, Currency = contributor.Currency, DateReceived = DateTime.Now,// contributor.DateReceived, DateDeposited = DateTime.Now,//contributor.DateDeposited, Comments = contributor.Comments }; // do we do the conversion here or on the UI? // later on in the UI, because it is easier to update.. we can add a field for conversion switch (contributor.Currency.ToUpper()) { case "INR": newContributorRecord.ConvertedAmount = contributor.OriginalCurrencyAmount; break; case "USD": newContributorRecord.ConvertedAmount = contributor.OriginalCurrencyAmount * 60; break; case "EUR": newContributorRecord.ConvertedAmount = contributor.OriginalCurrencyAmount * 75; break; default: newContributorRecord.ConvertedAmount = contributor.OriginalCurrencyAmount * 20; break; } orgMaintEntitiesContext.Contributors.Add(newContributorRecord); orgMaintEntitiesContext.SaveChanges(); BudgetHistory newBudgetHistoryRecord = new BudgetHistory { Amount = newContributorRecord.ConvertedAmount, DebitCredit = "Credit", Date = (DateTime)(newContributorRecord.DateDeposited == null ? DateTime.Now : newContributorRecord.DateDeposited), Comments = newContributorRecord.Comments, Principal = newContributorRecord.ContributorName }; orgMaintEntitiesContext.BudgetHistories.Add(newBudgetHistoryRecord); orgMaintEntitiesContext.SaveChanges(); var query = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (query == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = newContributorRecord.ConvertedAmount; budgStatu.BudgetAllocated = 0; budgStatu.BudgetRequired = 00; budgStatu.DateUpdated = DateTime.Now; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); } else { query.BudgetAvailable += newContributorRecord.ConvertedAmount; query.DateUpdated = (DateTime)(DateTime)(newContributorRecord.DateDeposited == null ? DateTime.Now : newContributorRecord.DateDeposited); } orgMaintEntitiesContext.SaveChanges(); updateEntityStatus(); return true; }
public EntitySummaryContract GetEntityStatusMixed() { EntitySummaryContract entityStatus = new EntitySummaryContract(); var query = (from entitySummary in orgMaintEntitiesContext.EntitySummaries select entitySummary).FirstOrDefault(); if (query == null) { EntitySummary newEntitySummary = new EntitySummary(); entityStatus.TotalEntities = newEntitySummary.TotalEntities = 0; entityStatus.TotalEntitiesAllocable = newEntitySummary.TotalEntitiesAllocable = 00; entityStatus.TotalEntitiesUnallocated = newEntitySummary.TotalEntitiesUnallocated = 00; entityStatus.DateUpdated = newEntitySummary.DateUpdated = DateTime.Now; entityStatus.DateUpdatedString = newEntitySummary.DateUpdated.ToShortDateString(); orgMaintEntitiesContext.EntitySummaries.Add(newEntitySummary); orgMaintEntitiesContext.SaveChanges(); } else { List<EntityFinanceSummaryContract> entityList = GetEntitySummaryList(); decimal budgetAvailable = 0 ; var query2 = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (query2 == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = 0; budgStatu.BudgetAllocated = 0; budgStatu.BudgetRequired = 00; budgStatu.DateUpdated = DateTime.Now; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); } else budgetAvailable = query2.BudgetAvailable; foreach(EntityFinanceSummaryContract entityElement in entityList) { query.TotalEntities += 1; if (entityElement.BudgetAllocated > 0) query.TotalEntitiesAllocated += 1; else if (budgetAvailable > 0) query.TotalEntitiesAllocable += 1; budgetAvailable -= entityElement.BudgetRequired; } if (budgetAvailable < 0) { query2.BudgetRequired = -1 * budgetAvailable; } /* var query = (from budgetStatusSingle in orgMaintEntitiesContext.BudgetStatus select budgetStatusSingle).FirstOrDefault(); if (query == null) { BudgetStatu budgStatu = new BudgetStatu(); budgStatu.BudgetAvailable = newContributorRecord.ConvertedAmount; budgStatu.BudgetAllocated = 0; budgStatu.BudgetRequired = 00; budgStatu.DateUpdated = DateTime.Now; orgMaintEntitiesContext.BudgetStatus.Add(budgStatu); } else { query.BudgetAvailable += newContributorRecord.ConvertedAmount; query.DateUpdated = (DateTime)(DateTime)(newContributorRecord.DateDeposited == null ? DateTime.Now : newContributorRecord.DateDeposited); } entityStatus.TotalEntities = 0; entityStatus.TotalEntitiesAllocable = 0; entityStatus.TotalEntitiesAllocated = 0; entityStatus.TotalEntitiesUnallocated = 0; var budgetStatus = BudgetStatusService.getBudgetStatus(); var budgetAvailable = budgetStatus.BudgetAvailable; var totalBudgetRequired = 0; for (i = 0; i < entityList.length; i++) { entityStatus.TotalEntities += 1; if (entityList[i].BudgetAllocated > 0) entityStatus.TotalEntitiesAllocated += 1; else if (budgetAvailable > 0) entityStatus.TotalEntitiesAllocable += 1; budgetAvailable -= entityList[i].BudgetRequired; } if (budgetAvailable < 0) { budgetStatus.BudgetRequired = -1 * budgetAvailable; BudgetStatusService.updateBudgetStatus(budgetStatus); } // if ($localStorage.debugMode == true) alert(entityStatus.TotalEntities); if ($localStorage.debugMode == true) alert(entityStatus.TotalEntitiesAllocated); if ($localStorage.debugMode == true) alert(entityStatus.TotalEntitiesAllocable); if (entityStatus.TotalEntities > (entityStatus.TotalEntitiesAllocated + entityStatus.TotalEntitiesAllocable)) entityStatus.TotalEntitiesUnallocated = entityStatus.TotalEntities - (entityStatus.TotalEntitiesAllocated + entityStatus.TotalEntitiesAllocable); return entityStatus; */ entityStatus.TotalEntities = query.TotalEntities; entityStatus.TotalEntities = query.TotalEntitiesAllocable; entityStatus.TotalEntitiesAllocated = query.TotalEntitiesAllocated; entityStatus.TotalEntitiesUnallocated = query.TotalEntitiesUnallocated; entityStatus.DateUpdated = query.DateUpdated; entityStatus.DateUpdatedString = query.DateUpdated.ToShortDateString(); } return entityStatus; }