9086c9ad77db90633e0629e9e86a88366265ded0
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

16) 
17) require_once('inc/base.php');
18) require_once('inc/security.php');
19) 
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

20) 
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

21) function my_invoices()
22) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

23)     $c = (int) $_SESSION['customerinfo']['customerno'];
24)     $result = db_query("SELECT id,datum,betrag,bezahlt,abbuchung,sepamandat FROM kundendaten.ausgestellte_rechnungen WHERE kunde=? ORDER BY id DESC", array($c));
25)     $ret = array();
26)     while ($line = $result->fetch()) {
27)         array_push($ret, $line);
28)     }
29)     return $ret;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

30) }
31) 
32) 
33) function get_pdf($id)
34) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

35)     $c = (int) $_SESSION['customerinfo']['customerno'];
36)     $id = (int) $id;
37)     $result = db_query("SELECT pdfdata FROM kundendaten.ausgestellte_rechnungen WHERE kunde=:c AND id=:id", array(":c" => $c, ":id" => $id));
38)     if ($result->rowCount() == 0) {
39)         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
40)     }
41)     return $result->fetch(PDO::FETCH_OBJ)->pdfdata;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

42) }
43) 
44) 
45) function invoice_details($id)
46) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

47)     $c = (int) $_SESSION['customerinfo']['customerno'];
48)     $id = (int) $id;
49)     $result = db_query("SELECT kunde,datum,betrag,bezahlt,abbuchung FROM kundendaten.ausgestellte_rechnungen WHERE kunde=:c AND id=:id", array(":c" => $c, ":id" => $id));
50)     if ($result->rowCount() == 0) {
51)         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
52)     }
53)     return $result->fetch();
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

54) }
55) 
56) function invoice_items($id)
57) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

58)     $c = (int) $_SESSION['customerinfo']['customerno'];
59)     $id = (int) $id;
60)     $result = db_query("SELECT id, beschreibung, datum, enddatum, betrag, einheit, brutto, mwst, anzahl FROM kundendaten.rechnungsposten WHERE rechnungsnummer=:id AND kunde=:c", array(":c" => $c, ":id" => $id));
61)     if ($result->rowCount() == 0) {
62)         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
63)     }
64)     $ret = array();
65)     while ($line = $result->fetch()) {
66)         array_push($ret, $line);
67)     }
68)     return $ret;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

69) }
70) 
71) 
72) function upcoming_items()
73) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

74)     $c = (int) $_SESSION['customerinfo']['customerno'];
75)     $result = db_query("SELECT quelle, id, anzahl, beschreibung, startdatum, enddatum, betrag, einheit, brutto, mwst FROM kundendaten.upcoming_items WHERE kunde=? ORDER BY startdatum ASC", array($c));
76)     $ret = array();
77)     while ($line = $result->fetch()) {
78)         array_push($ret, $line);
79)     }
80)     return $ret;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

81) }
82) 
83) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

84) function generate_qrcode_image($id)
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

85) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

86)     $invoice = invoice_details($id);
87)     $customerno = $invoice['kunde'];
88)     $amount = 'EUR'.sprintf('%.2f', $invoice['betrag']);
89)     $datum = $invoice['datum'];
90)     $data = 'BCD
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

91) 001
92) 1
93) SCT
94) GENODES1VBK
95) schokokeks.org GbR
96) DE91602911200041512006
97) '.$amount.'
98) 
99) 
Bernd Wurst Beschreibung entfernt, mach...

Bernd Wurst authored 10 years ago

100) RE '.$id.' KD '.$customerno.' vom '.$datum;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

101) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

102)     $descriptorspec = array(
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

103)     0 => array("pipe", "r"),  // STDIN ist eine Pipe, von der das Child liest
104)     1 => array("pipe", "w"),  // STDOUT ist eine Pipe, in die das Child schreibt
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

105)     2 => array("pipe", "w")
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

106)   );
107) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

108)     $process = proc_open('qrencode -t PNG -o - -l M', $descriptorspec, $pipes);
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

109) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

110)     if (is_resource($process)) {
111)         // $pipes sieht nun so aus:
112)         // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
113)         // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

114) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

115)         fwrite($pipes[0], $data);
116)         fclose($pipes[0]);
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

117) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

118)         $pngdata = stream_get_contents($pipes[1]);
119)         fclose($pipes[1]);
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

120) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

121)         // Es ist wichtig, dass Sie alle Pipes schließen bevor Sie
122)         // proc_close aufrufen, um Deadlocks zu vermeiden
123)         $return_value = proc_close($process);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

124) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

125)         return $pngdata;
126)     } else {
127)         warning('Es ist ein interner Fehler im Webinterface aufgetreten, aufgrund dessen kein QR-Code erstellt werden kann. Sollte dieser Fehler mehrfach auftreten, kontaktieren Sie bitte die Administratoren.');
128)     }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

129) }
130) 
131) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

132) function get_lastschrift($rechnungsnummer)
133) {
134)     $rechnungsnummer = (int) $rechnungsnummer;
135)     $result = db_query("SELECT rechnungsnummer, rechnungsdatum, sl.betrag, buchungsdatum, sl.status FROM kundendaten.sepalastschrift sl LEFT JOIN kundendaten.ausgestellte_rechnungen re ON (re.sepamandat=sl.mandatsreferenz) WHERE rechnungsnummer=?", array($rechnungsnummer));
136)     if ($result->rowCount() == 0) {
137)         return null;
138)     }
139)     $item = $result->fetch();
140)     return $item;
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

141) }
142) 
143) function get_lastschriften($mandatsreferenz)
144) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

145)     $result = db_query("SELECT rechnungsnummer, rechnungsdatum, betrag, buchungsdatum, status FROM kundendaten.sepalastschrift WHERE mandatsreferenz=? ORDER BY buchungsdatum DESC", array($mandatsreferenz));
146)     $ret = array();
147)     while ($item = $result->fetch()) {
148)         $ret[] = $item;
149)     }
150)     return $ret;
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

151) }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

152) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

153) function get_sepamandate()
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

154) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

155)     $cid = (int) $_SESSION['customerinfo']['customerno'];
156)     $result = db_query("SELECT id, mandatsreferenz, glaeubiger_id, erteilt, medium, gueltig_ab, gueltig_bis, erstlastschrift, kontoinhaber, adresse, iban, bic, bankname FROM kundendaten.sepamandat WHERE kunde=?", array($cid));
157)     $ret = array();
158)     while ($entry = $result->fetch()) {
159)         array_push($ret, $entry);
160)     }
161)     return $ret;
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

162) }
163) 
164) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

165) function yesterday($date)
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

166) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

167)     $result = db_query("SELECT ? - INTERVAL 1 DAY", array($date));
168)     return $result->fetch()[0];
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

169) }
170) 
171) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

172) function invalidate_sepamandat($id, $date)
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

173) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

174)     $args = array(":cid" => (int) $_SESSION['customerinfo']['customerno'],
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

175)                 ":id" => (int) $id,
176)                 ":date" => $date);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

177)     db_query("UPDATE kundendaten.sepamandat SET gueltig_bis=:date WHERE id=:id AND kunde=:cid", $args);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

178) }
179) 
180) 
181) function sepamandat($name, $adresse, $iban, $bankname, $bic, $gueltig_ab)
182) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

183)     $cid = (int) $_SESSION['customerinfo']['customerno'];
184) 
185)     $first_date = date('Y-m-d');
186)     $invoices = my_invoices();
187)     foreach ($invoices as $i) {
188)         if ($i['bezahlt'] == 0 && $i['datum'] < $first_date) {
189)             $first_date = $i['datum'];
190)         }
191)     }
192)     if ($gueltig_ab < date('Y-m-d') && $gueltig_ab != $first_date) {
193)         system_failure('Das Mandat kann nicht rückwirkend erteilt werden. Bitte geben Sie ein Datum in der Zukunft an.');
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

194)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

195)     $alte_mandate = get_sepamandate();
196)     $referenzen = array();
197)     foreach ($alte_mandate as $mandat) {
198)         if ($mandat['gueltig_bis'] == null || $mandat['gueltig_bis'] >= $gueltig_ab) {
199)             DEBUG('Altes Mandat wird für ungültig erklärt.');
200)             DEBUG($mandat);
201)             invalidate_sepamandat($mandat['id'], yesterday($gueltig_ab));
202)         }
203)         array_push($referenzen, $mandat['mandatsreferenz']);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

204)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

205)     $counter = 1;
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

206)     $referenz = sprintf('K%04d-M%03d', $cid, $counter);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

207)     while (in_array($referenz, $referenzen)) {
208)         $counter++;
209)         $referenz = sprintf('K%04d-M%03d', $cid, $counter);
210)     }
211)     DEBUG('Nächste freie Mandatsreferenz: '. $referenz);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

212) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

213)     $glaeubiger_id = config('glaeubiger_id');
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

214) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

215)     $today = date('Y-m-d');
216)     db_query(
217)       "INSERT INTO kundendaten.sepamandat (mandatsreferenz, glaeubiger_id, kunde, erteilt, medium, gueltig_ab, kontoinhaber, adresse, iban, bic, bankname) VALUES (:referenz, :glaeubiger_id, :cid, :today, 'online', :gueltig_ab, :name, :adresse, :iban, :bic, :bankname)",
218)           array(":referenz" => $referenz, ":glaeubiger_id" => $glaeubiger_id, ":cid" => $cid,
219)                 ":today" => $today, ":gueltig_ab" => $gueltig_ab, ":name" => $name, ":adresse" => $adresse,
220)                 ":iban" => $iban, ":bic" => $bic, ":bankname" => $bankname)
221)   );
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

222) }
223) 
224) 
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

225) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

226) function get_bank_info($iban)
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

227) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

228)     if (strlen($iban) != 22 || substr($iban, 0, 2) != 'DE') {
229)         // Geht nur bei deutschen IBANs
230)         echo 'Fehler!';
231)         echo '$iban = '.$iban;
232)         echo 'strlen($iban): '.strlen($iban);
233)         echo 'substr($iban, 0, 2): '.substr($iban, 0, 2);
234)         return null;
235)     }
236)     $blz = substr($iban, 4, 8);
237)     // FIXME: Liste der BLZs muss vorhanden sein!
238)     $bankinfofile = dirname(__FILE__).'/bankinfo.txt';
239)     $f = file($bankinfofile);
240)     $match = '';
241)     foreach ($f as $line) {
242)         if (substr($line, 0, 9) == $blz.'1') {
243)             $match = $line;
244)             break;
245)         }
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

246)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

247)     $bank = array();
248)     $bank['name'] = iconv('latin1', 'utf8', chop(substr($match, 9, 58)));
249)     $bank['bic'] = chop(substr($match, 139, 11));
250)     return $bank;
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

251) }
252) 
253) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

254) function find_iban($blz, $kto)
Bernd Wurst Ermögliche das Berechnen de...

Bernd Wurst authored 10 years ago

255) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

256)     $iban = sprintf('DE00%08s%010s', $blz, $kto);
257)     $iban = iban_set_checksum($iban);
258)     return $iban;
Bernd Wurst Ermögliche das Berechnen de...

Bernd Wurst authored 10 years ago

259) }
260) 
261) 
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

262) function get_customerquota()
263) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

264)     $cid = (int) $_SESSION['customerinfo']['customerno'];
265)     $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid", array(":cid" => $cid));
266)     $data = $result->fetch();
267)     return $data["quota"];
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

268) }
269) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

270) function save_more_storage($items, $storage)
271) {
272)     $cid = (int) $_SESSION['customerinfo']['customerno'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

273) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

274)     $queries = array();
275) 
276)     if ($storage < 1024 || $storage > 10240) {
277)         input_error('Speicherplatz nicht im erwarteten Bereich');
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

278)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

279)     $oldcustomerquota = get_customerquota();
280)     if ($oldcustomerquota > 102400) {
281)         # Über 100 GB soll die Automatik nichts machen
282)         system_failure("Ihr Speicherplatz kann über diese Funktion nicht weiter erhöht werden. Bitte wenden Sie sich an die Administratoren.");
283)     }
284)     $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid AND lastchange > CURDATE()", array(":cid" => $cid));
285)     if ($result->rowcount() > 0) {
286)         system_failure("Ihr Speicherplatz wurde heute bereits verändert. Sie können dies nur einmal am Tag machen.");
287)     }
288) 
289)     $queries[] = array("UPDATE system.customerquota SET quota=quota+:storage WHERE cid=:cid", array(":storage" => $storage, ":cid" => $cid));
290) 
291)     foreach ($items as $data) {
292)         if ($data['anzahl'] == 0) {
293)             continue;
294)         }
295)         $data['kunde'] = $cid;
296)         $data['notizen'] = 'Bestellt via Webinterface';
297)         if (!isset($data['anzahl']) ||
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

298)         !isset($data['beschreibung']) ||
299)         !isset($data['datum']) ||
300)         !array_key_exists('kuendigungsdatum', $data) ||
301)         !isset($data['betrag']) ||
302)         !isset($data['monate'])) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

303)             DEBUG($data);
304)             input_error("Ungültige Daten");
305)             return;
306)         }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

307) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

308)         $param = array();
309)         foreach ($data as $k => $v) {
310)             $param[':'.$k] = $v;
311)         }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

312) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

313)         $queries[] = array("INSERT INTO kundendaten.leistungen (kunde,periodisch,beschreibung,datum,kuendigungsdatum,betrag,brutto,monate,anzahl,notizen) VALUES ".
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

314)                        "(:kunde,1,:beschreibung,:datum,:kuendigungsdatum,:betrag,:brutto,:monate,:anzahl,:notizen)", $param);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

315)     }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

316) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

317)     if (count($queries) < 2) {
318)         system_failure("irgendwas stimmt jetzt nicht");
319)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

320) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

321)     foreach ($queries as $q) {
322)         db_query($q[0], $q[1]);
323)     }
324)     $allstorage = $oldcustomerquota+$storage;
325)     $emailaddr = $_SESSION['customerinfo']['email'];
326)     $message = "Hallo,\n\nsoeben wurde im Webinterface von ".config('company_name')." eine Bestellung über zusätzlichen Speicherplatz ausgeführt.\nSollten Sie diese Bestellung nicht getätigt haben, antworten Sie bitte auf diese E-Mail um unseren Support zu erreichen.\n\nBei dieser Bestellung wurden {$storage} MB zusätzlicher Speicherplatz bestellt. Ihnen stehen ab sofort insgesamt {$allstorage} MB zur Verfügung.\n\nIhre Kundennummer: {$_SESSION['customerinfo']['customerno']} ({$_SESSION['customerinfo']['name']})\n";
327)     mail($emailaddr, 'Auftragsbestätigung: Mehr Speicherplatz bei schokokeks.org', $message, "X-schokokeks-org-message: notify\nFrom: ".config('company_name').' <'.config('adminmail').">\nBcc: ".config('adminmail')."\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\n");