The best FMSC way is to, as you say, write the function in the model. But!! Don't do it in the AppModel, that's bad practice. Why would you put code related to two (at most) models in the AppModel?? Every model would inherit that function, that doesn't make much sense. Let's say you have a "Menu model" or an "User model", it isn't logical that they inherit a totalExpenses function, right? I understand that you want to have the function available in every controller and view if the need rises, but that's not the way to do it.
Step by step (actually, just two steps):
1) In the ExpenseClaim model, write a new function that will calculate the total of expenses
class ExpenseClaim extends AppModel {
/* definitions and validations here*/
public function totalExpenses($id) {
return $this->Expenses->find('count', array('conditions'=>
array('expense_claim_id' => $id)));
}
}
So, in the ExpenseClaimsController you can call this function with
$total = $this->ExpenseClaims->totalExpenses($the_id);
2) Now, it's logical to have the function that counts the total in the expenses claim model, and therefore available in the respective controller, but you said you wanted to use it in pages/admin_index, and let's imagine pages has absolutely no connection with the claim model. Well, then you can either do
ClassRegistry::init("ExpenseClaims")->totalExpenses($the_id);
or
$this->loadModel("ExpenseClaims");
$this->ExpenseClaims->totalExpenses($the_id);
(both in the controller) and you'll have that value available without putting that function in the AppModel.
(Btw, the code I wrote should work, but you need to fine tune the controllers and models names or close a parenthesis here and there, I haven't tested it).
Now, that's general best practice. Works in most cases, with more complicated functions. But for your case in specific, you may want to take a look at cake's counterCache, it keeps count of stuff without you having to do much.