main
 1using System;
 2using System.Collections.Generic;
 3using Gorilla.Commons.Utility;
 4using MoMoney.Domain.Core;
 5using gorilla.commons.utility;
 6
 7namespace MoMoney.Domain.Accounting
 8{
 9    public interface IBill : Entity
10    {
11        bool is_paid_for();
12        void pay(Money amount_to_pay);
13        ICompany company_to_pay { get; }
14        Money the_amount_owed { get; }
15        Date due_date { get; }
16    }
17
18    [Serializable]
19    public class Bill : GenericEntity<IBill>, IBill
20    {
21        IList<IPayment> payments { get; set; }
22
23        public Bill(ICompany company_to_pay, Money the_amount_owed, DateTime due_date)
24        {
25            this.company_to_pay = company_to_pay;
26            this.the_amount_owed = the_amount_owed;
27            this.due_date = due_date;
28            payments = new List<IPayment>();
29        }
30
31        public ICompany company_to_pay { get; private set; }
32        public Money the_amount_owed { get; private set; }
33        public Date due_date { get; private set; }
34
35        public bool is_paid_for()
36        {
37            return the_amount_paid().Equals(the_amount_owed);
38        }
39
40        public void pay(Money amount_to_pay)
41        {
42            payments.Add(new Payment(amount_to_pay));
43        }
44
45        Money the_amount_paid()
46        {
47            return payments.return_value_from_visiting_all_with(new TotalPaymentsCalculator());
48        }
49
50        public bool Equals(Bill obj)
51        {
52            if (ReferenceEquals(null, obj)) return false;
53            if (ReferenceEquals(this, obj)) return true;
54            return Equals(obj.company_to_pay, company_to_pay) && Equals(obj.the_amount_owed, the_amount_owed) &&
55                   obj.due_date.Equals(due_date);
56        }
57
58        public override bool Equals(object obj)
59        {
60            if (ReferenceEquals(null, obj)) return false;
61            if (ReferenceEquals(this, obj)) return true;
62            if (obj.GetType() != typeof (Bill)) return false;
63            return Equals((Bill) obj);
64        }
65
66        public override int GetHashCode()
67        {
68            unchecked
69            {
70                var result = (company_to_pay != null ? company_to_pay.GetHashCode() : 0);
71                result = (result*397) ^ (the_amount_owed != null ? the_amount_owed.GetHashCode() : 0);
72                result = (result*397) ^ due_date.GetHashCode();
73                return result;
74            }
75        }
76    }
77}