Funding an ira or roth ira
And on the last sentence, it doesn't matter when or where the money was earned (money is fungible, so there's generally not even any way to tell), but you do have to have sufficient earned income (that's basically money you earn from working, not from dividends and interest or selling stock and the like) in the contribution year to cover the IRA contribution.