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 ProjectNoFundingSourceCostTypeAmount(CostType costType, int?calendarYear, decimal amount) : this()
 {
     CostType     = costType;
     CostTypeID   = costType.CostTypeID;
     CalendarYear = calendarYear;
     Amount       = amount;
 }
Ejemplo n.º 3
0
 private ProjectFundingSourceCostTypeAmount(FundingSource fundingSource, CostType costType, int?calendarYear, decimal?monetaryAmount, bool isRealEntry)
 {
     FundingSource  = fundingSource;
     CostType       = costType;
     CalendarYear   = calendarYear;
     MonetaryAmount = monetaryAmount;
     IsRealEntry    = isRealEntry;
 }
 /// <summary>
 /// Enum types are equal by primary key
 /// </summary>
 public bool Equals(CostType other)
 {
     if (other == null)
     {
         return(false);
     }
     return(other.CostTypeID == CostTypeID);
 }
 /// <summary>
 /// Constructor for building a new object with MinimalConstructor required fields, using objects whenever possible
 /// </summary>
 public CostTypeDatamartMapping(CostType costType, string datamartObjectCode, string datamartObjectName, string datamartSubObjectCode, string datamartSubObjectName) : this()
 {
     // Mark this as a new object by setting primary key with special value
     this.CostTypeDatamartMappingID = ModelObjectHelpers.MakeNextUnsavedPrimaryKeyValue();
     this.CostTypeID            = costType.CostTypeID;
     this.DatamartObjectCode    = datamartObjectCode;
     this.DatamartObjectName    = datamartObjectName;
     this.DatamartSubObjectCode = datamartSubObjectCode;
     this.DatamartSubObjectName = datamartSubObjectName;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor for building a new object with MinimalConstructor required fields, using objects whenever possible
 /// </summary>
 public GrantAllocationBudgetLineItem(GrantAllocation grantAllocation, CostType costType, decimal grantAllocationBudgetLineItemAmount) : this()
 {
     // Mark this as a new object by setting primary key with special value
     this.GrantAllocationBudgetLineItemID = ModelObjectHelpers.MakeNextUnsavedPrimaryKeyValue();
     this.GrantAllocationID = grantAllocation.GrantAllocationID;
     this.GrantAllocation   = grantAllocation;
     grantAllocation.GrantAllocationBudgetLineItems.Add(this);
     this.CostTypeID = costType.CostTypeID;
     this.GrantAllocationBudgetLineItemAmount = grantAllocationBudgetLineItemAmount;
 }
Ejemplo n.º 7
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.º 8
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.º 11
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);
        }
Ejemplo n.º 12
0
 public ProjectCostTypeCalendarYearAmount(CostType costType, Dictionary <int, decimal?> calendarYearAmount)
 {
     CostType           = costType;
     CalendarYearAmount = calendarYearAmount;
 }
Ejemplo n.º 13
0
 private ProjectFundingSourceCostTypeAmount(FundingSource fundingSource, CostType costType, int?calendarYear, decimal?monetaryAmount, bool isRealEntry, bool isSecured) : this(fundingSource, costType, calendarYear, monetaryAmount, isRealEntry)
 {
     IsSecured = isSecured;
 }
Ejemplo n.º 14
0
 public ProjectCostTypeCalendarYearBudgetAmount(CostType costType, List <CalendarYearBudgetAmounts> calendarYearBudgetAmounts)
 {
     CostType = costType;
     CalendarYearBudgetAmounts = calendarYearBudgetAmounts;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a "blank" object of this type and populates primitives with defaults
 /// </summary>
 public static GrantAllocationBudgetLineItem CreateNewBlank(GrantAllocation grantAllocation, CostType costType)
 {
     return(new GrantAllocationBudgetLineItem(grantAllocation, costType, default(decimal)));
 }
Ejemplo n.º 16
0
 public CostTypeSimple(CostType costType)
 {
     CostTypeID   = costType.CostTypeID;
     CostTypeName = costType.CostTypeName;
 }
Ejemplo n.º 17
0
        public static decimal GetInvoicedToDateByCostType(this GrantAllocationAward grantAllocationAward, CostType costType)
        {
            decimal invoicedToDate = 0;

            switch (costType.CostTypeID)
            {
            case (int)CostTypeEnum.Contractual:
                invoicedToDate = grantAllocationAward.ContractualLineItemSum;
                break;

            case (int)CostTypeEnum.IndirectCosts:
                invoicedToDate = grantAllocationAward.IndirectCostTotal;
                break;

            case (int)CostTypeEnum.Supplies:
                invoicedToDate = grantAllocationAward.SuppliesLineItemAmountSum;
                break;

            case (int)CostTypeEnum.Travel:
                invoicedToDate = grantAllocationAward.TravelLineItemSum;
                break;

            case (int)CostTypeEnum.Personnel:
                invoicedToDate = grantAllocationAward.GrantAllocationAwardPersonnelAndBenefitsLineItems.Sum(pb => pb.GrantAllocationAwardPersonnelAndBenefitsLineItemHourlyTotal);
                break;

            case (int)CostTypeEnum.Benefits:
                invoicedToDate = grantAllocationAward.GrantAllocationAwardPersonnelAndBenefitsLineItems.Sum(pb => pb.GrantAllocationAwardPersonnelAndBenefitsLineItemFringeTotal);
                break;

            case (int)CostTypeEnum.Equipment:
            case (int)CostTypeEnum.Other:
                break;

            default:
                throw new Exception($"Unhandled CostTypeID {costType.CostTypeID} when trying to get the invoiced to date dollar amount for said cost type.");
            }

            return(invoicedToDate);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates a "blank" object of this type and populates primitives with defaults
 /// </summary>
 public static InvoiceLineItem CreateNewBlank(Invoice invoice, GrantAllocation grantAllocation, CostType costType)
 {
     return(new InvoiceLineItem(invoice, grantAllocation, costType, default(decimal)));
 }
 /// <summary>
 /// Creates a "blank" object of this type and populates primitives with defaults
 /// </summary>
 public static CostTypeDatamartMapping CreateNewBlank(CostType costType)
 {
     return(new CostTypeDatamartMapping(costType, default(string), default(string), default(string), default(string)));
 }