Rims and exhaust don't increase market value by all that much - maybe a grand at most.
If you can find similar cars for $38K, then obviously, you're better off buying one of those for $38K than paying $47K.
The sales tax advantage on a trade-in depends on the laws of the state you are in, including whether you get the same credit if you sell your car in a separate transaction; the percentage of sales tax; the value of your trade-in; etc. Do the math, and see how much the sales tax advantage is worth to you. Then factor that into your purchase decision. For example, if you are trading in a car worth $40K, and your state has 9 percent sales tax, then the trade-in reduces the amount of sales tax you pay on the purchase of a new car by $3600. If you would be willing to buy a similar car elsewhere for $38K, and you would be willing to sell your car for what the dealer is offering you on a trade-in, then you ought to be willing to buy that car from that dealer for $41,600 in this example.
Of course, if you can find lots of similar cars for $38K, you ought to show those ads to the dealership as part of your negotiations...
(Incidentally, most dealerships set an asking price that is a lot higher than they really expect to sell the car for. They expect to negotiate down and they build this into their asking price.)