public void CalculateRevenueRecognitions(int contractId)
        {
            Gateway  db              = new Gateway();
            var      contracts       = db.FindContract(contractId);
            Money    totalRevenue    = Money.Dollars((decimal)contracts.Rows[0]["Revenue"]);
            DateTime recognitionDate = (DateTime)contracts.Rows[0]["DateSigned"];
            string   type            = contracts.Rows[0]["Type"].ToString();

            if (type == "S")
            {
                Money[] allocation = totalRevenue.Allocate(3);
                db.InsertRecognitions(contractId, allocation[0], recognitionDate);
                db.InsertRecognitions(contractId, allocation[1], recognitionDate.AddDays(60));
                db.InsertRecognitions(contractId, allocation[2], recognitionDate.AddDays(90));
            }
            else if (type == "W")
            {
                db.InsertRecognitions(contractId, totalRevenue, recognitionDate);
            }
            else if (type == "D")
            {
                Money[] allocation = totalRevenue.Allocate(3);
                db.InsertRecognitions(contractId, allocation[0], recognitionDate);
                db.InsertRecognitions(contractId, allocation[1], recognitionDate.AddDays(30));
                db.InsertRecognitions(contractId, allocation[2], recognitionDate.AddDays(60));
            }
        }
Exemple #2
0
        public void TestAllocation()
        {
            Money money1 = new Money(10);

            Money[] allocatedMoney1 = money1.Allocate(3);
            Money   total1          = new Money();

            for (int i = 0; i < allocatedMoney1.Length; i++)
            {
                total1 += allocatedMoney1[i];
            }
            Assert.AreEqual("$10.00", total1.ToString());
            Assert.AreEqual("$3.34", allocatedMoney1[0].ToString());
            Assert.AreEqual("$3.33", allocatedMoney1[1].ToString());
            Assert.AreEqual("$3.33", allocatedMoney1[2].ToString());

            Money money2 = new Money(0.09m, CurrencyCodes.USD);

            Money[] allocatedMoney2 = money2.Allocate(5);
            Money   total2          = new Money(CurrencyCodes.USD);

            for (int i = 0; i < allocatedMoney2.Length; i++)
            {
                total2 += allocatedMoney2[i];
            }
            Assert.AreEqual("$0.09", total2.ToString());
        }
        public void AllocateTest1()
        {
            var target = new Money(100);
            var ratios = new[] { 0.2m };
            var expected = new[] { (Money)100 };

            Money[] actual = target.Allocate(ratios);

            for (int i = 0; i < ratios.Length; ++i)
                Assert.AreEqual(expected[i], actual[i]);
        }
Exemple #4
0
        public void Allocate_SixDollars_ReturnsFiveDollarNoteAndOneDollarNote()
        {
            var money = new Money(10, 10, 10, 10, 10, 10);

            var result = money.Allocate(6);

            result.FiveDollarsCount.Should().Be(1);
            result.OneDollarCount.Should().Be(1);
            result.QuarterCount.Should().Be(0);
            result.TenCentCount.Should().Be(0);
            result.OneCentCount.Should().Be(0);
        }
Exemple #5
0
		public void TestAllocation()
		{
			var money1 = new Money(10, CurrencyCodes.ZAR);
			var allocatedMoney1 = money1.Allocate(3);
			var total1 = new Money(CurrencyCodes.ZAR);

		    total1 = allocatedMoney1.Aggregate(total1, (current, t) => current + t);
		    Assert.AreEqual("R10,00", total1.ToString());
			Assert.AreEqual("R3,34", allocatedMoney1[0].ToString());
			Assert.AreEqual("R3,33", allocatedMoney1[1].ToString());
			Assert.AreEqual("R3,33", allocatedMoney1[2].ToString());

			var money2 = new Money(0.09m, CurrencyCodes.USD);
			var allocatedMoney2 = money2.Allocate(5);
			var total2 = new Money(CurrencyCodes.USD);
		    total2 = allocatedMoney2.Aggregate(total2, (current, t) => current + t);
		    Assert.AreEqual("$0.09", total2.ToString());
		}
Exemple #6
0
 public static Allocation Allocate(this Money money, int numberOfRecipients)
 {
     return(money.Allocate(numberOfRecipients, RemainderAllocator.FirstToLast));
 }
Exemple #7
0
 public static Allocation Allocate(this Money money, RatioCollection ratios)
 {
     return(money.Allocate(ratios, RemainderAllocator.FirstToLast));
 }