We consider a general compound Poisson risk model in which the premium rate is surplus dependent. We analyze the joint distribution of the surplus immediately before ruin, the deficit at ruin and the time of ruin by solving the integro-differential equation for the Gerber-Shiu discounted penalty function.