@@ -42,7 +42,7 @@ function invoke($action, $request, $dispatcher) {
4242function getMonatsSalden ($ kontonummer ) {
4343 if (is_numeric ($ kontonummer ) || $ this ->is_numeric_list ($ kontonummer )) {
4444 $ kto_prepared = $ this ->prepareKontoNummern ($ kontonummer );
45- $ db = getDbConnection ();
45+ $ pdo = getPdoConnection ();
4646 $ rechnungsart = $ this ->getRechnungsart ($ kto_prepared );
4747 if ($ rechnungsart != 0 ) {
4848 if ($ rechnungsart == 2 ) {
@@ -52,36 +52,38 @@ function getMonatsSalden($kontonummer) {
5252 ."(select (year(v.datum)*100)+month(v.datum) as groupingx, v.konto, v.betrag "
5353 ."from fi_ergebnisrechnungen_base v inner join fi_konto kt "
5454 ."on v.konto = kt.kontonummer and v.mandant_id = kt.mandant_id "
55- ."where v.mandant_id = $ this -> mandant_id "
55+ ."where v.mandant_id = : mandant_id "
5656 ."and v.gegenkontenart_id <> 5) as x "
5757 ."group by groupingx, konto) as y "
5858 ."where y.konto in ( $ kto_prepared) "
5959 ."and y.groupingx > ((year(now())*100)+month(now()))-100 "
6060 ."group by groupingx " ;
61-
62- $ rs = mysqli_query ($ db , $ sql );
61+ $ stmt = $ pdo ->prepare ($ sql );
62+ $ stmt ->execute (array (
63+ "mandant_id " => $ this ->mandant_id
64+ ));
6365 } else if ($ rechnungsart == 1 ) {
6466 // Laufende Summen, fuer Bestandskonten
6567 $ sql = "select x1.groupingx, sum(x2.betrag) as saldo "
6668 ."from (select distinct (year(datum)*100)+month(datum) as groupingx from fi_buchungen_view "
67- ."where mandant_id = ' $ this -> mandant_id ' ) x1 "
69+ ."where mandant_id = : mandant_id) x1 "
6870 ."inner join (select (year(datum)*100+month(datum)) as groupingx, konto, betrag "
69- ."from fi_buchungen_view where mandant_id = ' $ this -> mandant_id ' ) x2 "
71+ ."from fi_buchungen_view where mandant_id = : mandant_id) x2 "
7072 ."on x2.groupingx <= x1.groupingx "
7173 ."where konto in ( $ kto_prepared) and x1.groupingx > ((year(now())*100)+month(now()))-100 "
7274 ."group by groupingx " ;
7375
74- $ rs = mysqli_query ($ db , $ sql );
76+ $ stmt = $ pdo ->prepare ($ sql );
77+ $ stmt ->execute (array (
78+ "mandant_id " => $ this ->mandant_id
79+ ));
7580 }
7681 $ result = array ();
77- while ($ obj = mysqli_fetch_object ( $ rs )) {
82+ while ($ obj = $ stmt -> fetchObject ( )) {
7883 $ result [] = $ obj ;
7984 }
80- mysqli_free_result ($ rs );
81- mysqli_close ($ db );
8285 return wrap_response ($ result );
8386 } else {
84- mysqli_close ($ db );
8587 throw new Exception ("Mindestens eine Kontonummer ist unbekannt " );
8688 }
8789 } else throw new Exception ("Mindestens eine Kontonummer ist nicht numerisch " );
@@ -95,15 +97,15 @@ function getMonatsSalden($kontonummer) {
9597function getCashFlow ($ kontonummer , $ side ) {
9698 $ values = array ();
9799 if ($ this ->isAktivKonto ($ kontonummer )) {
98- $ db = getDbConnection ();
100+ $ pdo = getPdoConnection ();
99101
100102 if ($ side == 'S ' ) {
101103 $ sql = "select (year(datum)*100)+month(datum) as groupingx, sum(b.betrag) as saldo " ;
102104 $ sql .= "from fi_buchungen as b " ;
103105 $ sql .= " inner join fi_konto as k " ;
104106 $ sql .= " on k.mandant_id = b.mandant_id and k.kontonummer = b.habenkonto " ;
105- $ sql .= " where b.mandant_id = " . $ this -> mandant_id ;
106- $ sql .= " and b.sollkonto = ' " . $ kontonummer. " ' " ;
107+ $ sql .= " where b.mandant_id = : mandant_id " ;
108+ $ sql .= " and b.sollkonto = : kontonummer " ;
107109 $ sql .= " and year(b.datum) >= year(now())-1 " ;
108110 $ sql .= " and year(b.datum) <= year(now()) " ;
109111 $ sql .= " and k.kontenart_id <> 5 " ;
@@ -113,23 +115,24 @@ function getCashFlow($kontonummer, $side) {
113115 $ sql .= "from fi_buchungen as b " ;
114116 $ sql .= " inner join fi_konto as k " ;
115117 $ sql .= " on k.mandant_id = b.mandant_id and k.kontonummer = b.sollkonto " ;
116- $ sql .= " where b.mandant_id = " . $ this -> mandant_id ;
117- $ sql .= " and b.habenkonto = ' " . $ kontonummer. " ' " ;
118+ $ sql .= " where b.mandant_id = : mandant_id " ;
119+ $ sql .= " and b.habenkonto = : kontonummer " ;
118120 $ sql .= " and year(b.datum) >= year(now())-1 " ;
119121 $ sql .= " and year(b.datum) <= year(now()) " ;
120122 $ sql .= " and k.kontenart_id <> 5 " ;
121123 $ sql .= "group by (year(b.datum)*100)+month(b.datum); " ;
122124 } else {
123- mysqli_close ($ db );
124125 throw new Exception ("Gültige Werte für side sind S und H " );
125126 }
126127
127- $ rs = mysqli_query ($ db , $ sql );
128- while ($ obj = mysqli_fetch_object ($ rs )) {
128+ $ stmt = $ pdo ->prepare ($ sql );
129+ $ stmt ->execute (array (
130+ "mandant_id " => $ this ->mandant_id ,
131+ "kontonummer " => $ kontonummer
132+ ));
133+ while ($ obj = $ stmt ->fetchObject ()) {
129134 $ values [] = $ obj ;
130135 }
131- mysqli_free_result ($ rs );
132- mysqli_close ($ db );
133136 } else {
134137 throw new Exception ("getCashFlow ist nur für Aktiv-Konten verfügbar " );
135138 }
@@ -138,7 +141,7 @@ function getCashFlow($kontonummer, $side) {
138141
139142# Monats-internen Verlauf ermitteln
140143function getIntraMonth ($ request ) {
141- $ db = getDbConnection ();
144+ $ pdo = getPdoConnection ();
142145
143146 if (isset ($ request ['month_id ' ])) {
144147 if ($ this ->is_number ($ request ['month_id ' ])) {
@@ -151,14 +154,15 @@ function getIntraMonth($request) {
151154 $ sql = $ query ->getSql ();
152155
153156 $ result = array ();
154- $ rs = mysqli_query ($ db , $ sql );
155- while ($ obj = mysqli_fetch_object ($ rs )) {
157+ $ stmt = $ pdo ->query ($ sql );
158+ if ($ stmt === false ) {
159+ // Kein Ergebnis
160+ return wrap_response ([]);
161+ }
162+ while ($ obj = $ stmt ->fetchObject ()) {
156163 $ result [] = $ obj ;
157164 }
158165
159- mysqli_free_result ($ rs );
160- mysqli_close ($ db );
161-
162166 return wrap_response ($ result );
163167
164168 } else {
@@ -172,16 +176,19 @@ function getIntraMonth($request) {
172176# Prüft, ob das angegebene Konto ein Aktiv-Konto ist.
173177function isAktivKonto ($ kontonummer ) {
174178 if (!is_numeric ($ kontonummer )) return false ;
175- $ db = getDbConnection ();
176- $ rs = mysqli_query ($ db , "select kontenart_id from fi_konto "
177- ."where mandant_id = " .$ this ->mandant_id
178- ." and kontonummer = ' " .$ kontonummer ."' " );
179+ $ pdo = getPdoConnection ();
180+ $ sql = "select kontenart_id from fi_konto "
181+ ."where mandant_id = :mandant_id "
182+ ." and kontonummer = :kontonummer " ;
183+ $ stmt = $ pdo ->prepare ($ sql );
184+ $ stmt ->execute (array (
185+ "mandant_id " => $ this ->mandant_id ,
186+ "kontonummer " => $ kontonummer
187+ ));
179188 $ isActive = false ;
180- if ($ obj = mysqli_fetch_object ( $ rs )) {
189+ if ($ obj = $ stmt -> fetchObject ( )) {
181190 $ isActive = $ obj ->kontenart_id == 1 ; // Ist Aktiv-Konto
182191 }
183- mysqli_free_result ($ rs );
184- mysqli_close ($ db );
185192 return $ isActive ;
186193}
187194
@@ -234,12 +241,12 @@ function is_number($value) {
234241# eine GUV-Betrachtung (nur Aufwand und Ertrag) oder
235242# eine Bestandsbetrachtung (nur Aktiv und Passiv) handelt.
236243function getRechnungsart ($ kto_prepared ) {
237- $ db = getDbConnection ();
244+ $ pdo = getPdoConnection ();
238245 $ kontenarten = array ();
239246 $ type = 0 ;
240247 $ sql = "select distinct kontenart_id from fi_konto where kontonummer in ( $ kto_prepared) " ;
241- $ rs = mysqli_query ( $ db , $ sql );
242- while ($ obj = mysqli_fetch_object ( $ rs )) {
248+ $ stmt = $ pdo -> query ( $ sql );
249+ while ($ obj = $ stmt -> fetchObject ( )) {
243250 $ kontenart_id = $ obj ->kontenart_id ;
244251 if ($ type == 0 ) {
245252 // noch ERGEBNISOFFEN
@@ -253,8 +260,6 @@ function getRechnungsart($kto_prepared) {
253260 if ($ kontenart_id == 1 || $ kontenart_id == 2 ) throw new Exception ("Falsche Mischung von Kontenarten " );
254261 }
255262 }
256- mysqli_free_result ($ rs );
257- mysqli_close ($ db );
258263 return $ type ;
259264}
260265
0 commit comments