_freightRevenue += t.getValue();
switch (t.getSubcategory()) { case DeliverCargoReceipt.SUBCATEGORY_FREIGHT: _freightRevenue += t.getValue(); break; case DeliverCargoReceipt.SUBCATEGORY_PASSENGERS: _passengerRevenue += t.getValue(); break; }
    public ProfitLossModel(ModelRoot mr, int year) {	ReadOnlyWorld world = mr.getWorld();	Economy economy = (Economy) world.get(ITEM.ECONOMY,		mr.getPlayerPrincipal());	incomeTaxRatePercent = economy.getIncomeTaxRate();	GameCalendar calendar = (GameCalendar) world.get(ITEM.CALENDAR,		mr.getPlayerPrincipal());	GregorianCalendar calendarYear = new GregorianCalendar(year, 0, 1);	long deltaInMillis = calendarYear.getTimeInMillis() - (new		    GregorianCalendar(calendar.getStartYear(), 0,			1)).getTimeInMillis();	long deltaInTicks = deltaInMillis / (1000 * 60 * 60 * 24) *	    calendar.getTicksPerDay();	GameTime now = (GameTime) world.get(ITEM.TIME, mr.getPlayerPrincipal());	if (now.getTime() < deltaInTicks) {	    throw new IllegalArgumentException("This year hasn't arrived " +		    "yet!");	}	BankAccount account = (BankAccount) world.get(KEY.BANK_ACCOUNTS, 0,		mr.getPlayerPrincipal());	int nTransactions = account.size();	int i = 0;	while (i < account.size() &&		account.getTransaction(i).getTime().getTime() < deltaInTicks) {	    i++;	}	if (i == account.size()) {	    // TODO	    // everything == 0	}	int minIndex = i;	long yearEndInTicks = deltaInTicks + (calendar.getTicksPerDay() *		calendarYear.getActualMaximum(GregorianCalendar.DAY_OF_YEAR));	int maxIndex = i;	while (maxIndex < account.size() &&		account.getTransaction(maxIndex).getTime().getTime() <		yearEndInTicks) {	    maxIndex++;	}	/* calculate income for freight haulage */	/* TODO until accounting is changed, all cargo revenue is categorised	 * as freight */	long _freightRevenue = 0;	long _trackMaintenanceExpense = 0;	long _interestPayableExpense = 0;	long _rollingStockMaintenanceExpense = 0;	long _fuelExpenses = 0;	for (i = minIndex; i < maxIndex; i++) {	    Transaction t = account.getTransaction(i);	    switch (t.getCategory()) {		case Transaction.CATEGORY_COST_OF_SALES:		    if (t.getSubcategory() == Bill.FUEL)			_fuelExpenses -= t.getValue();		    break;		case Transaction.CATEGORY_REVENUE:		    _freightRevenue += t.getValue();		    break;		case Transaction.CATEGORY_OPERATING_EXPENSE:		    if (t.getSubcategory() == Bill.TRACK_MAINTENANCE)			_trackMaintenanceExpense -= t.getValue();		    else if (t.getSubcategory() ==			    Bill.ROLLING_STOCK_MAINTENANCE)			_rollingStockMaintenanceExpense -= t.getValue();		    break;		case Transaction.CATEGORY_INTEREST:		    _interestPayableExpense -= t.getValue();		    break;	    }	}	if (_interestPayableExpense < 0) {	    interestPayableExpense = 0;	} else {	    interestPayableExpense = _interestPayableExpense;	}	freightRevenue = _freightRevenue;	passengerRevenue = 0;	fuelExpenses = _fuelExpenses;	totalRevenue = freightRevenue + passengerRevenue;	grossProfit = totalRevenue - fuelExpenses;	trackMaintenanceExpense = _trackMaintenanceExpense;	rollingStockMaintenanceExpense = _rollingStockMaintenanceExpense;	profitBeforeTax = grossProfit - trackMaintenanceExpense -	    rollingStockMaintenanceExpense - interestPayableExpense;	totalExpenses = fuelExpenses + trackMaintenanceExpense +	    rollingStockMaintenanceExpense + interestPayableExpense;	incomeTax = profitBeforeTax > 0 ? profitBeforeTax *	    incomeTaxRatePercent / 100 : 0;	profitAfterTax = profitBeforeTax - incomeTax;    }