The quantum integrals associated to quantum Yetter-Drinfeld $\pi$-modules are defined. We shall prove the following affineness criterion: if there exists $\theta=\{\theta_{\beta}:H_{\beta}\to Hom(H_{\beta-1},A)\}_{\beta\in\pi}$ a total quantum integral and the canonical map $\chi:A\otimes_BA\to\bigoplus_{\gamma\in\pi}H_{\gamma}\otimes A$, $\chi(a\otimes_B b)=\bigoplus_{\gamma\in\pi}S_{\gamma}^{-1}\phi_{\alpha}(b_{[1,\alpha^{-1}\gamma^{-1}\alpha]}) b_{[0,0]}\langle-1,\gamma\rangle\otimes ab_{[0,0]\langle0,0\rangle}$ is surjective. Then the induction functor $-\otimes_B A:\Cal{U}_B\to^{H}\CalY\Cal D^{\alpha}_A$ is an equivalence of categories. The affineness criterion proven by Menini and Militaru is recovered as special cases.