示例#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();

                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);
                    }
                }
            }
        }
示例#2
0
        private void OnEndOfMonth(object sender, EventArgs e)
        {
            Finance     Accounts    = Resources.FinanceResource() as Finance;
            FinanceType bankAccount = Accounts.GetFirst();

            foreach (var overhead in this.Children.Where(a => a.GetType() == typeof(EnterpriseOverhead)).Cast <EnterpriseOverhead>().Where(a => a.NextDueDate.Year == Clock.Today.Year & a.NextDueDate.Month == Clock.Today.Month))
            {
                // make payment
                bankAccount.Remove(overhead.Amount, this.Name, overhead.Name);
                // update next due date
                overhead.NextDueDate = overhead.NextDueDate.AddMonths(overhead.PaymentInterval);
            }

            // make interest payments on bank accounts
            foreach (var item in Resources.FinanceResource().Children)
            {
                if (item.GetType() == typeof(FinanceType))
                {
                    FinanceType accnt = item as 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();

            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());
                }
            }
        }
示例#4
0
        private void OnWFAnimalSell(object sender, EventArgs e)
        {
            RuminantHerd ruminantHerd = Resources.RuminantHerd();

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

            int    trucks     = 0;
            double saleValue  = 0;
            double saleWeight = 0;
            int    head       = 0;

            // get current untrucked list of animals flagged for sale
            List <Ruminant> herd = ruminantHerd.Herd.Where(a => a.SaleFlag != Common.HerdChangeReason.None & a.Breed == BreedName).OrderByDescending(a => a.Weight).ToList();

            // if sale herd > min loads before allowing sale
            if (herd.Select(a => a.Weight / 450.0).Sum() / Number450kgPerTruck >= MinimumTrucksBeforeSelling)
            {
                // while truck to fill
                while (herd.Select(a => a.Weight / 450.0).Sum() / Number450kgPerTruck > MinimumLoadBeforeSelling)
                {
                    bool nonloaded = true;
                    trucks++;
                    double load450kgs = 0;
                    // while truck below carrying capacity load individuals
                    foreach (var ind in herd)
                    {
                        if (load450kgs + (ind.Weight / 450.0) <= Number450kgPerTruck)
                        {
                            nonloaded = false;
                            head++;
                            load450kgs += ind.Weight / 450.0;
                            RuminantValue getvalue = PriceList.Where(a => a.Age < ind.Age).OrderBy(a => a.Age).LastOrDefault();
                            saleValue  += getvalue.SellValue * ((getvalue.Style == Common.PricingStyleType.perKg) ? ind.Weight : 1.0);
                            saleWeight += ind.Weight;
                            ruminantHerd.RemoveRuminant(ind);
                        }
                    }
                    if (nonloaded)
                    {
                        Summary.WriteWarning(this, String.Format("There was a problem loading the sale truck as sale individuals did not meet the loading criteria for breed {0}", BreedName));
                        break;
                    }
                    herd = ruminantHerd.Herd.Where(a => a.SaleFlag != Common.HerdChangeReason.None & a.Breed == BreedName).OrderByDescending(a => a.Weight).ToList();
                }

                if (trucks > 0 & bankAccount != null)
                {
                    // calculate transport costs
                    double transportCost = trucks * DistanceToMarket * CostPerKmTrucking;
                    bankAccount.Remove(transportCost, this.Name, "Transport");
                    // calculate MLA fees
                    double mlaCost = head * MLAFees;
                    bankAccount.Remove(mlaCost, this.Name, "R&DFee");
                    // calculate yard fees
                    double yardCost = head * YardFees;
                    bankAccount.Remove(yardCost, this.Name, "YardCosts");
                    // calculate commission
                    double commissionCost = saleValue * SalesCommission;
                    bankAccount.Remove(commissionCost, this.Name, "SalesCommission");

                    // add and remove from bank
                    bankAccount.Add(saleValue, this.Name, "Sales");
                }
            }
        }