Doubt in the proof of Poincaire's theorem using Gauss-Bonnet theorem (local).

I'm studying differential geometry through the book "Differential Geometry of Curves and Surfaces - Manfredo P. do Carmo", and I have a doubt in the demonstration of Poincare's Theorem.

POINCARE'S THEOREM. The sum of the indices of a diferentiable vector field $v$ with isolated singular points on a compact surface $S$ is equal to the Euler-Poincaré characteristic of the surface $S$.

The proof uses Gauss-Bonnet Theorem (local)

GAUSS-BONNET THEOREM (Local). Let $x$: $U\subset \mathbb{R}^2$ $\rightarrow$ $S$ be an orthogonal parametrization (that is, $\langle x_u,x_v\rangle = 0$), of an oriented surface $S$, where $U$ $\subset$ $\mathbb{R}^2$ is homeomorphic to an open disk and $x$ is compatible with the orientation of $S$. Let $R$ $\subset$ $x(U)$ be a simple region of $S$ and let $\alpha$: $I$ $\rightarrow$ $S$ be such that $\partial R$ $=$ $\alpha(I)$. Assume that a is positively oriented, parametrized by arc length $s$, and let $\alpha(s_0)$, . . . , $\alpha(s_k)$ and $\theta_0$, . . . ,$\theta_k$, be, respectively, the vertices and the external angles of $\alpha$. Then $$\sum_{i=0}^{k} \int_{s_{i}}^{s_{i+1}}k_g + \int \int_R K dS + \sum_{i=0}^{k} \theta_i = 2\pi$$ where $k_g(s)$ is the geodesic curvature of the regular arcs of a and $K$ is the Gaussian curvature of $S$.

To prove this Manfredo proposes the following solution:

Let $S$ $\subset$ $\mathbb{R}^3$ be an oriented, compact surface and $v$ a differentiable vector field with only isolated singular points. We remark that they are finite in number. Otherwise, by compactness, they have a limit point which is a nonisolated singular point. Let $\{x_{\alpha}\}$ be a family of orthogonal parametrizations compatible with the orientation of $S$. Let $\mathcal{T}$ be a triangulation of $S$ such that

1. Every triangle $T$ $\in$ $\mathcal{T}$ is contained in some coordinate neighborhood of the family $\{x_\alpha\}$.
2. Every $T$ $\in$ $\mathcal{T}$ contains at most one singular point.
3. The boundary of every $T$ $\in$ $\mathcal{T}$ contains no singular points and is positively oriented.

If we apply GAUSS-BONNET THEOREM (Local) , sum up the results, and take into account that the edge of each $T$ $\in$ $\mathcal{T}$ appears twice with opposite orientations, we obtain

$$\int \int_S K d\sigma - 2\pi\sum_{i=0}^{k} I_i = 0$$

where $I_i$ is the index of the singular point $p_i$, $i = 1$, . . . , $k.$ Joining this with the Gauss-Bonnet theorem (Global), we finally arrive at

$$\sum_{i=0}^{k} I_i = \frac{1}{2\pi} \int \int_S K d\sigma = \chi (S). \quad \mbox{Q.E.D.}$$

My problem is in the part marked in bold above. If we use Gauss-Bonnet on $T$ $\in$ $\mathcal{T}$ we get

$$\int_{\partial T} k_g + \int \int_{T} K dS + \sum_{i=0}^{2} \theta_{iT} = 2\pi$$

If we sum up the equation above for all $T$ $\in$ $\mathcal{T}$.

\begin{align*} \sum_{T \in \mathcal{T}}\left(\int_{\partial T} k_g + \int \int_{T} K dS + \sum_{i=0}^{2} \theta_{iT} \right) =& \sum_{T \in \mathcal{T}} 2\pi \\ \sum_{T \in \mathcal{T}} \int_{\partial T} k_g + \sum_{T \in \mathcal{T}} \int \int_{T} K dS + \sum_{T \in \mathcal{T}} \sum_{i=0}^{2} \theta_{iT} =& 2\pi \hspace{0.1cm}\# \mathcal{T} \\ 0+ \int \int_S K dS + \sum_{T \in \mathcal{T}}\sum_{i=0}^{2} \theta_{iT} - 2\pi \hspace{0.1cm}\# \mathcal{T} &= 0. \\ \end{align*} Where $\# \mathcal{T}$ $=$ number of elements of the set $\mathcal{T}$.

My Question: Why $$\sum_{T \in \mathcal{T}}\sum_{i=0}^{2} \theta_{iT} - 2\pi \hspace{0.1cm}\# \mathcal{T} = 2 \pi \sum_{i=0}^{k} I_i \hspace{0.1 cm} ?$$

First of all, let me reformulate your problem. Let X be a smooth tangent vector field on a compact oriented surface S, with isolated singularities ${p_1 , . . . , p_n }$. Then the sum of the indices of the singularities, \begin{equation} \sum_{k=1}^{n} I_k(X,p_k) \end{equation} depends only on S and not on the vector field. The sum of the indices is equal to the the Euler characteristic $\chi(S)$ of the surface S.
The basic idea to prove this theorem starts by recalling the fact that the rotation number is $(2 \pi)^{−1}$ times the total curvature, i.e. \begin{equation} rot(\gamma)=\frac{1}{2 \pi} \int_{\gamma} k_g(t) |\gamma'(t)| dt =\frac{1}{2 \pi} \int_{\gamma} k_g(s) ds \end{equation} where $\gamma$ is a smooth regular closed curve. Then we can compute the rotation index for the “boundary curves” of each of the faces in a subdivision and finally add the results up.
It should be noted that the sign of the rotation index depends on whether you move along the curve in the positive or negative direction. Consider now a triangulation, i.e. a collection of curved triangles such that any point on the surface either lies on one of the curves or in a region bounded by a curve triangle. Now by joining the arcs forming each triangles, we obtain a continuous closed curve, so that we can define the rotation number of the regular piecewise smooth curve $\gamma$ to be the winding number of this loop. However we have to face a problem. The definition of the rotation number above applies to smooth regular closed curves, i.e. smooth Jordan curves, while in our case the boundaries of faces are piecewise smooth. As a matter of fact the tangent vector jumps at the vertices. When thinking to the meaning of the curvature, i.e. the magnitude of the rate of change of the unit tangent vector, when accounting for the angular changes in the tangent vector, we can generalize the rotation index to: \begin{equation} rot(\gamma)=\frac{1}{2 \pi} \big( \int_{\gamma} k_g(s) ds + \sum_i \theta_i \big) \end{equation} where $\gamma$ is now a regular piecewise smooth curve and $\theta_i$ is the $i^{th}$ external angle. For a regular piecewise smooth Jordan curve, i.e. plane simple closed curves, oriented in the positive direction, $rot(\gamma)$ is equal to 1. When adding singulatities the situation is different. It should be noted that for each curve $\gamma_k$ used to build up $\gamma$ we have $I_k(X,p_k)=rot(\gamma_k)$. However when considering $\gamma$, $rot(\gamma)=\sum_{k=1}^{n} wn(\gamma, p_k) I_k(X,p_k)$ where wn is the winding number. Then \begin{equation} rot(\gamma)=1-\sum_{k} I_k(X,p_k) \end{equation} We assumed that all the singularities of X are in the interiors of faces, so that for each $\gamma$ which bounds a face we can write: \begin{equation} 1-\sum_{k} I_k(X,p_k) =\frac{1}{2 \pi} \big( \int_{\gamma} k_g(s) ds + \sum_i \theta_i \big) \end{equation} By applying Gauss-Bonnet local \begin{equation} 1-\sum_{k} I_k(X,p_k) =\frac{1}{2 \pi} \big( 2 \pi - \iint_S K dS \big) \end{equation} And then \begin{equation} \sum_{k} I_k(X,p_k) =\frac{1}{2 \pi} \iint_S K dS \end{equation} You can now apply the Gauss-Bonnet theorem global to conclude that \begin{equation} \sum_{k=1}^{n} I_k(X,p_k) = \chi(S) \end{equation} To avoid any confusion please consider that the rotation number and winding number are not necessarely equals. Informally, the winding number of a closed curve is the number of times the curve winds around a point. On the other hand, the rotation number is the number of rotations made by the tangent vector during one traversal of the curve. You can see the rotation number of a regular closed curve as the winding number of its derivative around the origin, or more intuitively, the total number of times that a person walking once around the curve turns counterclockwise.