multiplicities of flat pullbacks Let $f:X\to Y$ be a flat morphism between two Noetherian, integral, regular schemes. Let $D\in \operatorname{Div}(Y)$ any (Weil or Cartier) divisor, in this setting it has sense to consider the pullback $\,f^\ast D\in\operatorname{Div }(X)$.
Define the ramification index of $f$ at $x$ as:
$$e_x:=\operatorname{length}_{\mathcal O_{X,x}}\frac{\mathcal O_{X,x}}{\mathfrak m_{f(x)}\mathcal O_{X,x}}$$
I'd like to show that the following formula is true:

$$f^\ast D=\sum_{x\in\star} e_x\operatorname{mult}_{f(x)}(D)\overline{\{x\}}$$
  where $\star$ is the set of points $x\in X$ of codimension $1$ such that also $f(x)$ has codimension $1$. This formula is very important indeed it gives an explicit way to calculate the pullback of a divisor.

Can you give an hint for the proof or give any references? For instance the Stack project reference given here is wrong (probably the document has been updated).
Many thanks in advance.
 A: $\require{AMScd}$
$\newcommand{\spec}[1]{\mathrm{Spec}(#1)}$
$\newcommand{\tensor}{\otimes}$
$\newcommand{\ideal}[1]{\mathfrak{#1}}$
Let $f^*D$ be the left side of the equation and $f^\sharp D$ the right side of the equation. Then we note first that both sides are linear in $D$.
Consider the square
$$
\begin{CD}
X @<j'<< X' \\
@VVfV     @VVf'V \\
Y @<j<< Y'
\end{CD}
$$
where $j:Y' \to Y$ and $j':X' \to X$ are open immersions, and $f' = f|_{X'}$.
We assume, that $f'^*D = f'^\sharp D$ and we note 
$$j'^\sharp f^\sharp D = f'^\sharp j^\sharp D$$
and
$$
\begin{align}
j^* D = j^\sharp D \\
j'^* E = j'^\sharp E
\end{align}
$$ 
for all divisors $D$ on $Y$ and $E$ on $X$.
Then
$$
\begin{equation}
j'^* f^* D = f'^* j^*D = f'^\sharp j^*D = f'^\sharp j^\sharp D = j'^\sharp f^\sharp D = j'^* f^\sharp D
\end{equation}
$$
As $X'$ and $Y'$ can vary over a cover of $f:X \to Y$ we have $f^*D = f^\sharp D$ provided this holds for every $f':X' \to Y'$ where $X'=\spec{B}$ and $Y'=\spec{A}$ are open affine subschemes of $X$ and $Y$.
So we can assume that $X=\spec{B}$, $Y=\spec{A}$ and (because of linearity and locality) that $D=(a)$ where $a$ is a nonzerodivisor of $A$.
Then $f^*D = (a)$ where $a$ is considered as element of $B$. It is a non-zero-divisor because $ -\tensor_A B$ is exact on $0 \to A \xrightarrow{\cdot a} A$.
Now choose a minimal prime $\ideal{q} \supseteq aB$, so that $\ideal{p} = \ideal{q} \cap A \supseteq (a)$ is a minimal prime over $aA$ (this follows from the going down property of the flat $B/A$).
The equation to be proved then reduces to the form
$$
\mathrm{len} B_\ideal{q}/a B_\ideal{q} = \mathrm{len} (B_\ideal{q}/\ideal{p} B_\ideal{q}) \mathrm{len} (A_\ideal{p}/a A_\ideal{p}) 
$$
But this follows from the cited Stacks 51.13 with $A = A_\ideal{p}$, $B = B_\ideal{q}$ and $M = A/aA$.
