c86e41f63bce496e5191dec1755f95e8806e5b58
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) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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) {
23)   $c = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

24)   $result = db_query("SELECT id,datum,betrag,bezahlt,abbuchung,sepamandat FROM kundendaten.ausgestellte_rechnungen WHERE kunde=? ORDER BY id DESC", array($c));
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

25)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

26)   while($line = $result->fetch())
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

27)   	array_push($ret, $line);
28)   return $ret;
29) }
30) 
31) 
32) function get_pdf($id)
33) {
34)   $c = (int) $_SESSION['customerinfo']['customerno'];
35)   $id = (int) $id;
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

36)   $result = db_query("SELECT pdfdata FROM kundendaten.ausgestellte_rechnungen WHERE kunde=:c AND id=:id",array(":c" => $c, ":id" => $id));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

37)   if ($result->rowCount() == 0)
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

38) 	  system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

39)   return $result->fetch(PDO::FETCH_OBJ)->pdfdata;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

40) 
41) }
42) 
43) 
44) function invoice_details($id)
45) {
46)   $c = (int) $_SESSION['customerinfo']['customerno'];
47)   $id = (int) $id;
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

48)   $result = db_query("SELECT kunde,datum,betrag,bezahlt,abbuchung FROM kundendaten.ausgestellte_rechnungen WHERE kunde=:c AND id=:id",array(":c" => $c, ":id" => $id));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

49)   if ($result->rowCount() == 0)
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

50)   	system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

51)   return $result->fetch();
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

52) }
53) 
54) function invoice_items($id)
55) {
56)   $c = (int) $_SESSION['customerinfo']['customerno'];
57)   $id = (int) $id;
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

58)   $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));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

59)   if ($result->rowCount() == 0)
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

60)   	system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

61)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

62)   while($line = $result->fetch())
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

63)   array_push($ret, $line);
64)   return $ret;
65) }
66) 
67) 
68) function upcoming_items()
69) {
70)   $c = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

71)   $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));
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

72)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

73)   while($line = $result->fetch())
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

74) 	  array_push($ret, $line);
75)   return $ret;
76) }
77) 
78) 
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

79) function generate_qrcode_image($id) 
80) {
81)   $invoice = invoice_details($id);
82)   $customerno = $invoice['kunde'];
83)   $amount = 'EUR'.sprintf('%.2f', $invoice['betrag']);
84)   $datum = $invoice['datum'];
85)   $data = 'BCD
86) 001
87) 1
88) SCT
89) GENODES1VBK
90) schokokeks.org GbR
91) DE91602911200041512006
92) '.$amount.'
93) 
94) 
Bernd Wurst Beschreibung entfernt, mach...

Bernd Wurst authored 10 years ago

95) RE '.$id.' KD '.$customerno.' vom '.$datum;
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

96)   
97)   $descriptorspec = array(
98)     0 => array("pipe", "r"),  // STDIN ist eine Pipe, von der das Child liest
99)     1 => array("pipe", "w"),  // STDOUT ist eine Pipe, in die das Child schreibt
100)     2 => array("pipe", "w") 
101)   );
102) 
103)   $process = proc_open('qrencode -t PNG -o - -l M', $descriptorspec, $pipes);
104) 
105)   if (is_resource($process)) {
106)     // $pipes sieht nun so aus:
107)     // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
108)     // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
109) 
110)     fwrite($pipes[0], $data);
111)     fclose($pipes[0]);
112) 
113)     $pngdata = stream_get_contents($pipes[1]);
114)     fclose($pipes[1]);
115) 
116)     // Es ist wichtig, dass Sie alle Pipes schließen bevor Sie
117)     // proc_close aufrufen, um Deadlocks zu vermeiden
118)     $return_value = proc_close($process);
119)   
120)     return $pngdata;
121)   } else {
122)     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.');
123)   }
124) }
125) 
126) 
127) function generate_bezahlcode_image($id) 
128) {
129)   $invoice = invoice_details($id);
130)   $customerno = $invoice['kunde'];
131)   $amount = str_replace('.', '%2C', sprintf('%.2f', $invoice['betrag']));
132)   $datum = $invoice['datum'];
133)   $data = 'bank://singlepaymentsepa?name=schokokeks.org%20GbR&reason=RE%20'.$id.'%20KD%20'.$customerno.'%20vom%20'.$datum.'&iban=DE91602911200041512006&bic=GENODES1VBK&amount='.$amount;
134)   
135)   $descriptorspec = array(
136)     0 => array("pipe", "r"),  // STDIN ist eine Pipe, von der das Child liest
137)     1 => array("pipe", "w"),  // STDOUT ist eine Pipe, in die das Child schreibt
138)     2 => array("pipe", "w") 
139)   );
140) 
141)   $process = proc_open('qrencode -t PNG -o -', $descriptorspec, $pipes);
142) 
143)   if (is_resource($process)) {
144)     // $pipes sieht nun so aus:
145)     // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
146)     // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
147) 
148)     fwrite($pipes[0], $data);
149)     fclose($pipes[0]);
150) 
151)     $pngdata = stream_get_contents($pipes[1]);
152)     fclose($pipes[1]);
153) 
154)     // Es ist wichtig, dass Sie alle Pipes schließen bevor Sie
155)     // proc_close aufrufen, um Deadlocks zu vermeiden
156)     $return_value = proc_close($process);
157)   
158)     return $pngdata;
159)   } else {
160)     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.');
161)   }
162) }
163) 
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

164) function get_lastschrift($rechnungsnummer) {
165)   $rechnungsnummer = (int) $rechnungsnummer;
Bernd Wurst Zeige Rechnungen zu rückgeb...

Bernd Wurst authored 9 years ago

166)   $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=? AND re.abbuchung=1", array($rechnungsnummer));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

167)   if ($result->rowCount() == 0) {
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

168)     return NULL;
169)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

170)   $item = $result->fetch();
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

171)   return $item;
172) }
173) 
174) function get_lastschriften($mandatsreferenz)
175) {
Bernd Wurst Zeige Rechnungen zu rückgeb...

Bernd Wurst authored 9 years ago

176)   $result = db_query("SELECT rechnungsnummer, rechnungsdatum, betrag, buchungsdatum, status FROM kundendaten.sepalastschrift WHERE mandatsreferenz=? ORDER BY buchungsdatum DESC", array($mandatsreferenz));
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

177)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

178)   while ($item = $result->fetch()) {
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

179)     $ret[] = $item;
180)   }
181)   return $ret;
182) }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

183) 
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

184) function get_sepamandate() 
185) {
186)   $cid = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

187)   $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));
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

188)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

189)   while ($entry = $result->fetch()) {
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

190)     array_push($ret, $entry);
191)   }
192)   return $ret;
193) }
194) 
195) 
196) function yesterday($date) 
197) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

198)   $result = db_query("SELECT ? - INTERVAL 1 DAY", array($date));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

199)   return $result->fetch()[0];
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

200) }
201) 
202) 
203) function invalidate_sepamandat($id, $date) 
204) {
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

205)   $args = array(":cid" => (int) $_SESSION['customerinfo']['customerno'],
206)                 ":id" => (int) $id,
207)                 ":date" => $date);
208)   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

209) }
210) 
211) 
212) function sepamandat($name, $adresse, $iban, $bankname, $bic, $gueltig_ab)
213) {
214)   $cid = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

215) 
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

216)   $first_date = date('Y-m-d');
217)   $invoices = my_invoices();
218)   foreach ($invoices as $i) {
219)     if ($i['bezahlt'] == 0 && $i['datum'] < $first_date) {
220)       $first_date = $i['datum'];
221)     }
222)   }
223)   if ($gueltig_ab < date('Y-m-d') && $gueltig_ab != $first_date) {
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

224)     system_failure('Das Mandat kann nicht rückwirkend erteilt werden. Bitte geben Sie ein Datum in der Zukunft an.');
225)   }
226)   $alte_mandate = get_sepamandate();
227)   $referenzen = array();
228)   foreach ($alte_mandate as $mandat) {
229)     if ($mandat['gueltig_bis'] == NULL || $mandat['gueltig_bis'] >= $gueltig_ab) {
230)       DEBUG('Altes Mandat wird für ungültig erklärt.');
231)       DEBUG($mandat);
232)       invalidate_sepamandat($mandat['id'], yesterday($gueltig_ab));
233)     }
234)     array_push($referenzen, $mandat['mandatsreferenz']);
235)   }
236)   $counter = 1;
237)   $referenz = sprintf('K%04d-M%03d', $cid, $counter);
238)   while (in_array($referenz, $referenzen)) {
239)     $counter++;
240)     $referenz = sprintf('K%04d-M%03d', $cid, $counter);
241)   }
242)   DEBUG('Nächste freie Mandatsreferenz: '. $referenz);
243) 
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

244)   $glaeubiger_id = config('glaeubiger_id');
245) 
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

246)   $today = date('Y-m-d');
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

247)   db_query("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)",
248)           array(":referenz" => $referenz, ":glaeubiger_id" => $glaeubiger_id, ":cid" => $cid, 
249)                 ":today" => $today, ":gueltig_ab" => $gueltig_ab, ":name" => $name, ":adresse" => $adresse, 
250)                 ":iban" => $iban, ":bic" => $bic, ":bankname" => $bankname));
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

251) }
252) 
253) 
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

254) 
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

255) function get_bank_info($iban) 
256) {
257)   if (strlen($iban) != 22 || substr($iban, 0, 2) != 'DE') {
258)     // Geht nur bei deutschen IBANs
259)     echo 'Fehler!';
260)     echo '$iban = '.$iban;
261)     echo 'strlen($iban): '.strlen($iban);
262)     echo 'substr($iban, 0, 2): '.substr($iban, 0, 2);
263)     return NULL;
264)   }
265)   $blz = substr($iban, 4, 8);
266)   // FIXME: Liste der BLZs muss vorhanden sein!
267)   $bankinfofile = dirname(__FILE__).'/bankinfo.txt';
268)   $f = file($bankinfofile);
269)   $match = '';
270)   foreach ($f as $line) {
271)     if (substr($line, 0, 9) == $blz.'1') {
272)       $match = $line;
273)       break;
274)     }
275)   }
276)   $bank = array();
277)   $bank['name'] = iconv('latin1', 'utf8', chop(substr($match, 9,58)));
278)   $bank['bic'] = chop(substr($match, 139,11));
279)   return $bank;
280) }
281) 
282) 
Bernd Wurst Ermögliche das Berechnen de...

Bernd Wurst authored 10 years ago

283) function find_iban($blz, $kto) 
284) {
285)   $iban = sprintf('DE00%08s%010s', $blz, $kto);
286)   $iban = iban_set_checksum($iban);
287)   return $iban;
288) }
289) 
290) 
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

291) function get_customerquota()
292) {
293)   $cid = (int) $_SESSION['customerinfo']['customerno'];
294)   $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid", array(":cid" => $cid));
295)   $data = $result->fetch();
296)   return $data["quota"];
297) }
298) 
299) function save_more_storage($items, $storage) {
300)   $cid = (int) $_SESSION['customerinfo']['customerno'];
301)   
302)   $queries = array();  
303) 
304)   if ($storage < 1024 || $storage > 10240) {
305)     input_error('Speicherplatz nicht im erwarteten Bereich');
306)   }
307)   $oldcustomerquota = get_customerquota();
Bernd Wurst E-mail-notification bei Spe...

Bernd Wurst authored 7 years ago

308)   if ($oldcustomerquota > 102400) {
309)     # Über 100 GB soll die Automatik nichts machen
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

310)     system_failure("Ihr Speicherplatz kann über diese Funktion nicht weiter erhöht werden. Bitte wenden Sie sich an die Administratoren.");
311)   }
Bernd Wurst Bugfix: Speicherplatz erhöh...

Bernd Wurst authored 7 years ago

312)   $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid AND lastchange > CURDATE()", array(":cid" => $cid));
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

313)   if ($result->rowcount() > 0) {
314)     system_failure("Ihr Speicherplatz wurde heute bereits verändert. Sie können dies nur einmal am Tag machen.");
315)   }
316) 
317)   $queries[] = array("UPDATE system.customerquota SET quota=quota+:storage WHERE cid=:cid", array(":storage" => $storage, ":cid" => $cid));
318) 
319)   foreach ($items as $data) {
320)     if ($data['anzahl'] == 0) {
321)       continue;
322)     }
323)     $data['kunde'] = $cid;
324)     $data['notizen'] = 'Bestellt via Webinterface';
325)     if (!isset($data['anzahl']) ||
326)         !isset($data['beschreibung']) ||
327)         !isset($data['datum']) ||
328)         !array_key_exists('kuendigungsdatum', $data) ||
329)         !isset($data['betrag']) ||
330)         !isset($data['monate'])) {
331)       DEBUG($data);
332)       input_error("Ungültige Daten");
333)       return;
334)     }
335)  
336)     $param = array();
337)     foreach ($data as $k => $v) {
338)       $param[':'.$k] = $v;
339)     }
340) 
341)     $queries[] = array("INSERT INTO kundendaten.leistungen (kunde,periodisch,beschreibung,datum,kuendigungsdatum,betrag,brutto,monate,anzahl,notizen) VALUES ".
342)                        "(:kunde,1,:beschreibung,:datum,:kuendigungsdatum,:betrag,:brutto,:monate,:anzahl,:notizen)", $param);
343)   }
344) 
345)   if (count($queries) < 2) {
346)     system_failure("irgendwas stimmt jetzt nicht");
347)   }
348)   
349)   foreach ($queries as $q) {
350)     db_query($q[0], $q[1]);
351)   }
Bernd Wurst E-mail-notification bei Spe...

Bernd Wurst authored 7 years ago

352)   $allstorage = $oldcustomerquota+$storage;
353)   $emailaddr = $_SESSION['customerinfo']['email'];
354)   $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.";
355)   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");
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

356) }
357)