Let $\Omega$ be a domain with smooth boundary $\partial \Omega$, $\bar{\Omega}$ is compact.
The Neumann problem:$f \in C^{\infty}(\bar{\Omega})$,$g\in C^{\infty}(\partial \bar{\Omega})$. Find a function $\varphi \in C^{\infty}(\bar{\Omega})$ satisfying $\Delta \varphi=f$ on $\bar{\Omega}$ and $\frac{\partial}{\partial \overrightarrow{n}}\varphi=g$ on $\partial \bar{\Omega}$. ($\Delta$ is the Laplace operator, $\overrightarrow{n}$ is the unit normal vector field.)
How to prove the Neumann problem has a solution if and only if $\int_{\bar\Omega}{fdx}=\int_{\partial \bar{\Omega}}{gdS}$ ?
Maybe I can solve the case of $g=0$.
Edit: I have changed the proof of the \eqref{cc}$ \implies $\eqref{np} to correct an error in the reasoning pointed out by the asker. The development is now necessarily more complicated but entirely correct. I'd like to thank Prof. Alberto Cialdea for the useful discussion on the topic and the suggestion to use Fredholm theory and the equivalent Neumann problem for the Laplace equation.
What we want to prove is that the following Neumann problem $$ \color{green}{ \begin{cases} \Delta \varphi(x)=f(x) & x\in\bar{\Omega}\\ \frac{\partial}{\partial \vec{n}}\varphi(x)=g(x)& x\in\partial\bar{\Omega} \end{cases}\label{np}\tag{NP}} $$ is solvable if and only if the following compatibility condition $$ \color{blue}{ \int\limits_\bar{\Omega}f(x)\mathrm{d}x=\int\limits_{\partial\bar{\Omega}}g(x)\mathrm{d}\sigma_x. \label{cc}\tag{CC}} $$ holds (with obvious meaning of the symbols), i.e. \eqref{np}$ \iff $\eqref{cc}. Let's proceed with proving the two opposite implications.
Final notes on the method of proof of the implication \eqref{cc}$ \implies $\eqref{np}.
[1] V. P. Mikhailov (1978), Partial differential equations, Translated from the Russian by P.C. Sinha. Revised from the 1976 Russian ed., Moscow: Mir Publishers, p. 396 MR0601389, Zbl 0388.3500.
[2] V. S. Vladimirov (1971)[1967], Equations of mathematical physics, Translated from the Russian original (1967) by Audrey Littlewood. Edited by Alan Jeffrey, (English), Pure and Applied Mathematics, Vol. 3, New York: Marcel Dekker, Inc., pp. vi+418, MR0268497, Zbl 0207.09101.