Пример #1
0
        private void OnWFResourcesAllocated(object sender, EventArgs e)
        {
            List <LabourOffFarmFilterGroup> taskList = this.Children.Where(a => a.GetType() == typeof(LabourOffFarmFilterGroup)).Cast <LabourOffFarmFilterGroup>().ToList();

            if (taskList.Count > 0)
            {
                Finance     Accounts    = Resources.FinanceResource() as Finance;
                FinanceType bankAccount = Accounts.GetFirst() as FinanceType;

                if (bankAccount != null)
                {
                    // search through arbitrators requests and make payments.

                    // otherwise we need to know who had payments made for work.



                    int month = Clock.Today.Month - 1;
                    foreach (var item in taskList)
                    {
                        // days provided from labour set in item.AmountProvided

                        // receive payment for labour
                        bankAccount.Add(item.AmountProvided, this.Name, item.Name);
                    }
                }
            }
        }
        private void OnEndOfMonth(object sender, EventArgs e)
        {
            FinanceType bankAccount = Resources.FinanceResource().GetFirst() as FinanceType;

            // make interest payments on bank accounts
            foreach (FinanceType accnt in Resources.FinanceResource().Children.Where(a => a.GetType() == typeof(FinanceType)))
            {
                if (accnt.Balance > 0)
                {
                    bankAccount.Add(accnt.Balance * accnt.InterestRatePaid / 1200, this.Name, "InterestPaid");
                }
                else
                {
                    bankAccount.Remove(Math.Abs(accnt.Balance) * accnt.InterestRateCharged / 1200, this.Name, "InterestCharged");
                }
            }
        }
Пример #3
0
        private void OnWFAnimalBuy(object sender, EventArgs e)
        {
            RuminantHerd ruminantHerd = Resources.RuminantHerd();

            Finance     Accounts    = Resources.FinanceResource() as Finance;
            FinanceType bankAccount = Accounts.GetFirst() as FinanceType;

            var newRequests = ruminantHerd.PurchaseIndividuals.Where(a => a.BreedParams.Breed == BreedName).ToList();

            foreach (var newgroup in newRequests.GroupBy(a => a.SaleFlag))
            {
                double fundsAvailable = 100000000;
                if (bankAccount != null)
                {
                    fundsAvailable = bankAccount.FundsAvailable;
                }
                double cost = 0;
                foreach (var newind in newgroup)
                {
                    double value = 0;
                    if (newgroup.Key == Common.HerdChangeReason.SirePurchase)
                    {
                        value = BreedingSirePrice;
                    }
                    else
                    {
                        RuminantValue getvalue = PriceList.Where(a => a.Age < newind.Age).OrderBy(a => a.Age).LastOrDefault();
                        value = getvalue.PurchaseValue * ((getvalue.Style == Common.PricingStyleType.perKg) ? newind.Weight : 1.0);
                    }
                    if (cost + value <= fundsAvailable)
                    {
                        ruminantHerd.AddRuminant(newind);
                        cost += value;
                    }
                    else
                    {
                        break;
                    }
                }
                if (bankAccount != null)
                {
                    bankAccount.Remove(cost, this.Name, newgroup.Key.ToString());
                }
            }
        }