variable totalamount function