public List <PaymentHistoryLineItem> GetAmountsPaid()
        {
            List <PaymentHistoryLineItem> items = new List <PaymentHistoryLineItem>();

            foreach (Payout payout in _payoutLookup.Values)
            {
                if (payout.Open)
                {
                    _payoutDescriptionOverride[payout.Identity] = Resources.Global.Financial_UnconfirmedPayout;
                }

                PaymentHistoryLineItem newItem = new PaymentHistoryLineItem();
                newItem.Id = "PO" + payout.Identity.ToString(CultureInfo.InvariantCulture);
                if (_payoutDescriptionOverride.ContainsKey(payout.Identity))
                {
                    newItem.Name = _payoutDescriptionOverride[payout.Identity];
                }
                else
                {
                    newItem.Name = String.Format(Resources.Global.Financial_PayoutSpecification, payout.Identity);
                }
                newItem.Description  = String.Empty;
                newItem.PaidToPerson = payout.AmountCents;
                newItem.OpenedDate   = payout.CreatedDateTime;

                if (!payout.Open)
                {
                    FinancialTransaction closeTx = payout.FinancialTransaction;
                    newItem.ClosedDate = closeTx.DateTime;
                }

                items.Add(newItem);
            }

            return(items);
        }
        public List <PaymentHistoryLineItem> GetAmountsOwed()
        {
            List <PaymentHistoryLineItem> items = new List <PaymentHistoryLineItem>();

            // Expense claims

            ExpenseClaims expenses = ExpenseClaims.FromClaimingPersonAndOrganization(_person,
                                                                                     _authenticationData.CurrentOrganization);

            foreach (ExpenseClaim claim in expenses)
            {
                if (claim.Open || claim.PaidOut) // if both these are false, the claim was denied and shouldn't be listed
                {
                    PaymentHistoryLineItem newItem = new PaymentHistoryLineItem();
                    newItem.Id           = "E" + claim.Identity.ToString(CultureInfo.InvariantCulture);
                    newItem.Name         = String.Format(Resources.Global.Financial_ExpenseClaimLongSpecification, claim.Identity);
                    newItem.Description  = claim.Description;
                    newItem.OpenedDate   = claim.CreatedDateTime;
                    newItem.OwedToPerson = claim.AmountCents;

                    Payout payout = claim.Payout;
                    if (payout != null && payout.Open == false)
                    {
                        _payoutLookup[payout.Identity] = payout;
                        newItem.ClosedDate             = payout.FinancialTransaction.DateTime;
                    }

                    items.Add(newItem);
                }
            }

            // Salaries

            Salaries salaries = Salaries.ForPersonAndOrganization(_person, _authenticationData.CurrentOrganization, true);

            foreach (Salary salary in salaries)
            {
                if (salary.Open || salary.NetPaid) // either of these must be open for the salary to be valid
                {
                    PaymentHistoryLineItem newItem = new PaymentHistoryLineItem();
                    newItem.Id           = "S" + salary.Identity.ToString(CultureInfo.InvariantCulture);
                    newItem.Name         = Resources.Global.Financial_Salary;
                    newItem.Description  = String.Format(Resources.Global.Financial_SalaryDualSpecification, salary.Identity, salary.PayoutDate);
                    newItem.OwedToPerson = salary.NetSalaryCents;

                    FinancialTransaction openTx = FinancialTransaction.FromDependency(salary);
                    if (openTx != null)
                    {
                        newItem.OpenedDate = openTx.DateTime;
                    }

                    Payout payout = Payout.FromDependency(salary, FinancialDependencyType.Salary);
                    if (payout != null && payout.Open == false)
                    {
                        _payoutLookup[payout.Identity] = payout;
                        newItem.ClosedDate             = payout.FinancialTransaction.DateTime;
                    }

                    items.Add(newItem);
                }
            }

            // Cash advances

            CashAdvances advances = CashAdvances.ForPersonAndOrganization(_person,
                                                                          _authenticationData.CurrentOrganization, true);

            foreach (CashAdvance advance in advances)
            {
                if (advance.Open || advance.PaidOut)
                {
                    Payout payout = advance.PayoutOut;
                    if (payout != null)
                    {
                        _payoutLookup[payout.Identity] = payout;
                        _payoutDescriptionOverride[payout.Identity] =
                            String.Format(Resources.Global.Financial_CashAdvanceSpecification, advance.Identity.ToString("N0"));
                    }
                }
            }

            return(items);
        }
 public static int LineItemSorterByDate(PaymentHistoryLineItem a, PaymentHistoryLineItem b)
 {
     return(a.OpenedDate.CompareTo(b.OpenedDate));
 }