Ejemplo n.º 1
0
        public static List <GrantAllocationBudgetLineItem> CreateAllGrantAllocationBudgetLineItemsByCostType(this GrantAllocation grantAllocation)
        {
            var grantAllocationBudgetLineItems = new List <GrantAllocationBudgetLineItem>();
            var shouldSaveChanges = false;

            foreach (var costType in CostType.GetLineItemCostTypes())
            {
                var lineItemByCostType = grantAllocation.GrantAllocationBudgetLineItems.SingleOrDefault(bli => bli.CostTypeID == costType.CostTypeID);
                if (lineItemByCostType == null)
                {
                    var tempLineItem = new GrantAllocationBudgetLineItem(grantAllocation.GrantAllocationID, costType.CostTypeID, 0);
                    lineItemByCostType = HttpRequestStorage.DatabaseEntities.GrantAllocationBudgetLineItems.Add(tempLineItem);

                    shouldSaveChanges = true;
                }
                grantAllocationBudgetLineItems.Add(lineItemByCostType);
            }

            if (shouldSaveChanges)
            {
                HttpRequestStorage.DatabaseEntities.SaveChanges();
            }

            return(grantAllocationBudgetLineItems);
        }
Ejemplo n.º 2
0
        public static decimal GetTotalInvoicedToDate(this GrantAllocationAward grantAllocationAward)
        {
            decimal totalInvoicedToDate = 0;

            foreach (var costType in CostType.GetLineItemCostTypes())
            {
                totalInvoicedToDate += grantAllocationAward.GetInvoicedToDateByCostType(costType);
            }

            return(totalInvoicedToDate);
        }
Ejemplo n.º 3
0
        public void CheckForMissingGrantAllocationBudgetLineItems()
        {
            var grantAllocations              = HttpRequestStorage.DatabaseEntities.GrantAllocations;
            var costTypeIdsForLineItems       = CostType.GetLineItemCostTypes().Select(x => x.CostTypeID).ToList();
            int countOfMissingBudgetLineItems = 0;

            //The key is the grantAllocationID and the value is a list of CostTypeIDs that the GrantAllocation is missing budget line items for
            Dictionary <int, List <int> > grantAllocationsAndTheCostTypesMissing = new Dictionary <int, List <int> >();

            foreach (var grantAllocation in grantAllocations)
            {
                var currentGrantAllocationBudgetLineItemCostTypeIds = grantAllocation.GrantAllocationBudgetLineItems.Select(x => x.CostTypeID).ToList();
                var idsNeeded = costTypeIdsForLineItems.Except(currentGrantAllocationBudgetLineItemCostTypeIds).ToList();
                if (idsNeeded.Any())
                {
                    grantAllocationsAndTheCostTypesMissing.Add(grantAllocation.GrantAllocationID, idsNeeded);
                    countOfMissingBudgetLineItems += idsNeeded.Count;
                }
            }

            var message = grantAllocationsAndTheCostTypesMissing.Select(x => $"grantAllocationID:{x.Key} costTypeID:{string.Join(",",x.Value)}");

            Assert.That(!grantAllocationsAndTheCostTypesMissing.Any(), $"There are GrantAllocations missing GrantAllocationBudgetLineItems. There are {countOfMissingBudgetLineItems} missing BudgetLineItems. Here they are: {string.Join(" | ",message)}");

            /*
             *  Here is the SQL needed to find and add all missing GrantAllocationBudgetLineItems:
             *  select *
             *  into
             #tmpGrantAllocationBudgetLineItemsToCreate
             *  from
             *  (
             *      select
             *          ga.GrantAllocationID,
             *          ct.CostTypeID
             *      from
             *          dbo.GrantAllocation as ga
             *      cross join dbo.CostType as ct
             *      left outer join dbo.GrantAllocationBudgetLineItem as bli
             *          on bli.GrantAllocationID = ga.GrantAllocationID and bli.CostTypeID = ct.CostTypeID
             *      where
             *          bli.GrantAllocationBudgetLineItemID IS NULL AND
             *          ct.IsValidInvoiceLineItemCostType = 1
             *  ) as myData
             *
             *  INSERT INTO dbo.GrantAllocationBudgetLineItem(GrantAllocationID, CostTypeID, GrantAllocationBudgetLineItemAmount)
             *  SELECT
             *          GrantAllocationID as GrantAllocationID,
             *          CostTypeID as CostTypeID,
             *          0 as GrantAllocationBudgetLineItemAmount
             *  FROM
             #tmpGrantAllocationBudgetLineItemsToCreate
             *
             */
        }
        public void GivenBadCostTypeWhenInvoiceSavedThenFails()
        {
            var invalidCostTypeItems = CostType.All.Except(CostType.GetLineItemCostTypes());

            foreach (var costType in invalidCostTypeItems)
            {
                var item = TestFramework.TestInvoiceLineItem.Create(HttpRequestStorage.DatabaseEntities, costType);
                Assert.IsNotNull(item, "should get item");
                Assert.Catch(() => HttpRequestStorage.DatabaseEntities.SaveChanges(), "Database save should catch on constraint and fail");
                Assert.That(!ModelObjectHelpers.IsRealPrimaryKeyValue(item.PrimaryKey), "does not have primary key in database");
            }
        }
        public void CheckForValidInsertOfInvoiceLineItemForAllValidCostTypes()
        {
            var lineItemCostTypes = CostType.GetLineItemCostTypes();

            foreach (var costType in lineItemCostTypes)
            {
                var item = TestFramework.TestInvoiceLineItem.Create(HttpRequestStorage.DatabaseEntities, costType);
                Assert.IsNotNull(item, "should get item");
                Assert.DoesNotThrow(() => HttpRequestStorage.DatabaseEntities.SaveChanges(), "Should be able to create for these types");
                Assert.That(ModelObjectHelpers.IsRealPrimaryKeyValue(item.PrimaryKey), "has primary key in database");
            }
        }
Ejemplo n.º 6
0
        public static List <BudgetVsActualLineItem> GetAllBudgetVsActualLineItemsByCostType(this GrantAllocation grantAllocation)
        {
            var budgetVsActualsLineItemList = new List <BudgetVsActualLineItem>();

            foreach (var costType in CostType.GetLineItemCostTypes())
            {
                var budget = grantAllocation.GrantAllocationBudgetLineItems.Where(bli => bli.CostTypeID == costType.CostTypeID).Select(bli => bli.GrantAllocationBudgetLineItemAmount).Sum();

                var expendituresFromDatamart = grantAllocation.GrantAllocationExpenditures
                                               .Where(gae => gae.CostTypeID == costType.CostTypeID).Select(gae => gae.ExpenditureAmount).Sum();

                var invoicedToDate = grantAllocation.GrantAllocationAwards.Sum(grantAllocationAward => grantAllocationAward.GetInvoicedToDateByCostType(costType));


                var budgetVsActualLineItem = new BudgetVsActualLineItem(costType, budget, expendituresFromDatamart, invoicedToDate);
                budgetVsActualsLineItemList.Add(budgetVsActualLineItem);
            }

            return(budgetVsActualsLineItemList);
        }