7e8f9039f3d47e100856f03c5a7d05fb5376c41f
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) 
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 9 years ago

129)   $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

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

Bernd Wurst authored 10 years ago

131)     return NULL;
132)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

134)   return $item;
135) }
136) 
137) function get_lastschriften($mandatsreferenz)
138) {
Bernd Wurst Zeige Rechnungen zu rückgeb...

Bernd Wurst authored 9 years ago

139)   $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

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

142)     $ret[] = $item;
143)   }
144)   return $ret;
145) }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

147) function get_sepamandate() 
148) {
149)   $cid = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

150)   $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

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

153)     array_push($ret, $entry);
154)   }
155)   return $ret;
156) }
157) 
158) 
159) function yesterday($date) 
160) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

163) }
164) 
165) 
166) function invalidate_sepamandat($id, $date) 
167) {
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

168)   $args = array(":cid" => (int) $_SESSION['customerinfo']['customerno'],
169)                 ":id" => (int) $id,
170)                 ":date" => $date);
171)   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

172) }
173) 
174) 
175) function sepamandat($name, $adresse, $iban, $bankname, $bic, $gueltig_ab)
176) {
177)   $cid = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

179)   $first_date = date('Y-m-d');
180)   $invoices = my_invoices();
181)   foreach ($invoices as $i) {
182)     if ($i['bezahlt'] == 0 && $i['datum'] < $first_date) {
183)       $first_date = $i['datum'];
184)     }
185)   }
186)   if ($gueltig_ab < date('Y-m-d') && $gueltig_ab != $first_date) {
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

187)     system_failure('Das Mandat kann nicht rückwirkend erteilt werden. Bitte geben Sie ein Datum in der Zukunft an.');
188)   }
189)   $alte_mandate = get_sepamandate();
190)   $referenzen = array();
191)   foreach ($alte_mandate as $mandat) {
192)     if ($mandat['gueltig_bis'] == NULL || $mandat['gueltig_bis'] >= $gueltig_ab) {
193)       DEBUG('Altes Mandat wird für ungültig erklärt.');
194)       DEBUG($mandat);
195)       invalidate_sepamandat($mandat['id'], yesterday($gueltig_ab));
196)     }
197)     array_push($referenzen, $mandat['mandatsreferenz']);
198)   }
199)   $counter = 1;
200)   $referenz = sprintf('K%04d-M%03d', $cid, $counter);
201)   while (in_array($referenz, $referenzen)) {
202)     $counter++;
203)     $referenz = sprintf('K%04d-M%03d', $cid, $counter);
204)   }
205)   DEBUG('Nächste freie Mandatsreferenz: '. $referenz);
206) 
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

210)   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)",
211)           array(":referenz" => $referenz, ":glaeubiger_id" => $glaeubiger_id, ":cid" => $cid, 
212)                 ":today" => $today, ":gueltig_ab" => $gueltig_ab, ":name" => $name, ":adresse" => $adresse, 
213)                 ":iban" => $iban, ":bic" => $bic, ":bankname" => $bankname));
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

214) }
215) 
216) 
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

218) function get_bank_info($iban) 
219) {
220)   if (strlen($iban) != 22 || substr($iban, 0, 2) != 'DE') {
221)     // Geht nur bei deutschen IBANs
222)     echo 'Fehler!';
223)     echo '$iban = '.$iban;
224)     echo 'strlen($iban): '.strlen($iban);
225)     echo 'substr($iban, 0, 2): '.substr($iban, 0, 2);
226)     return NULL;
227)   }
228)   $blz = substr($iban, 4, 8);
229)   // FIXME: Liste der BLZs muss vorhanden sein!
230)   $bankinfofile = dirname(__FILE__).'/bankinfo.txt';
231)   $f = file($bankinfofile);
232)   $match = '';
233)   foreach ($f as $line) {
234)     if (substr($line, 0, 9) == $blz.'1') {
235)       $match = $line;
236)       break;
237)     }
238)   }
239)   $bank = array();
240)   $bank['name'] = iconv('latin1', 'utf8', chop(substr($match, 9,58)));
241)   $bank['bic'] = chop(substr($match, 139,11));
242)   return $bank;
243) }
244) 
245) 
Bernd Wurst Ermögliche das Berechnen de...

Bernd Wurst authored 10 years ago

246) function find_iban($blz, $kto) 
247) {
248)   $iban = sprintf('DE00%08s%010s', $blz, $kto);
249)   $iban = iban_set_checksum($iban);
250)   return $iban;
251) }
252) 
253) 
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

254) function get_customerquota()
255) {
256)   $cid = (int) $_SESSION['customerinfo']['customerno'];
257)   $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid", array(":cid" => $cid));
258)   $data = $result->fetch();
259)   return $data["quota"];
260) }
261) 
262) function save_more_storage($items, $storage) {
263)   $cid = (int) $_SESSION['customerinfo']['customerno'];
264)   
265)   $queries = array();  
266) 
267)   if ($storage < 1024 || $storage > 10240) {
268)     input_error('Speicherplatz nicht im erwarteten Bereich');
269)   }
270)   $oldcustomerquota = get_customerquota();
Bernd Wurst E-mail-notification bei Spe...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

275)   $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

276)   if ($result->rowcount() > 0) {
277)     system_failure("Ihr Speicherplatz wurde heute bereits verändert. Sie können dies nur einmal am Tag machen.");
278)   }
279) 
280)   $queries[] = array("UPDATE system.customerquota SET quota=quota+:storage WHERE cid=:cid", array(":storage" => $storage, ":cid" => $cid));
281) 
282)   foreach ($items as $data) {
283)     if ($data['anzahl'] == 0) {
284)       continue;
285)     }
286)     $data['kunde'] = $cid;
287)     $data['notizen'] = 'Bestellt via Webinterface';
288)     if (!isset($data['anzahl']) ||
289)         !isset($data['beschreibung']) ||
290)         !isset($data['datum']) ||
291)         !array_key_exists('kuendigungsdatum', $data) ||
292)         !isset($data['betrag']) ||
293)         !isset($data['monate'])) {
294)       DEBUG($data);
295)       input_error("Ungültige Daten");
296)       return;
297)     }
298)  
299)     $param = array();
300)     foreach ($data as $k => $v) {
301)       $param[':'.$k] = $v;
302)     }
303) 
304)     $queries[] = array("INSERT INTO kundendaten.leistungen (kunde,periodisch,beschreibung,datum,kuendigungsdatum,betrag,brutto,monate,anzahl,notizen) VALUES ".
305)                        "(:kunde,1,:beschreibung,:datum,:kuendigungsdatum,:betrag,:brutto,:monate,:anzahl,:notizen)", $param);
306)   }
307) 
308)   if (count($queries) < 2) {
309)     system_failure("irgendwas stimmt jetzt nicht");
310)   }
311)   
312)   foreach ($queries as $q) {
313)     db_query($q[0], $q[1]);
314)   }
Bernd Wurst E-mail-notification bei Spe...

Bernd Wurst authored 7 years ago

315)   $allstorage = $oldcustomerquota+$storage;
316)   $emailaddr = $_SESSION['customerinfo']['email'];
Bernd Wurst Zeige Kundennummer/Name in...

Bernd Wurst authored 6 years ago

317)   $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";
Bernd Wurst E-mail-notification bei Spe...

Bernd Wurst authored 7 years ago

318)   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

319) }
320)