4963b3db3066e945b1c36747a5d20015df7a119e
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 4 years ago

1) <?php
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

2) require_once('api.php');
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 4 years ago

3) 
Bernd Wurst Suche phonetisch (oe/ue usw.)

Bernd Wurst authored 1 month ago

4) 
5) function phonetisch_reduzieren($word)
6) {
7)     $word=strtolower($word);
8)     $substitution=array(
9)             "ä"=>"ae",
10)             "ö"=>"oe",
11)             "ü"=>"ue",
12)             "ß"=>"ss",
13)             "ph"=>"f"
14)             );
15) 
16)     foreach ($substitution as $letter=>$substitution) {
17)         $word=str_replace($letter,$substitution,$word);
18)     }
19)     return $word;
20) }
21) 
22) 
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 4 years ago

23) function suche_kunde($name, $number) {
24)         global $content;
25)         if (! $number) {
26)             return NULL;
27)         }
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

28)         $ret = api_call('GET', 'customerContacts/search/'.format_number_api($number));
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 1 year ago

29)         if ($ret['status_code'] >= 400) {
30)             foreach ($ret['data']['validation_errors'] as $item) {
31)                 $_SESSION['warning'][] = $item['message'];
32)             }
33)             return null;
34)         }
35)         $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

36)         if (count($ret) > 0) {
37)             $name = strtolower($name);
38)             foreach ($ret as $item) {
39)                 $cust = $item['customer'];
Bernd Wurst Suche phonetisch (oe/ue usw.)

Bernd Wurst authored 1 month ago

40)                 if ((isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['lastname'])) ||
41)                     (isset($cust['firstname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['firstname'])) ||
42)                     (isset($cust['firstname']) && isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['firstname'] .' '. $cust['lastname'])) ||
43)                     (isset($cust['firstname']) && isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['lastname'] .' '. $cust['firstname'])) ||
44)                     (isset($cust['firstname']) && isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['lastname'] .', '. $cust['firstname']))
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

45)                     ) {
46)                     return $cust;
47)                 }
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 4 years ago

48)             }
49)         }
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

50)         return null;
51) 
52)         /*
53)         $kundenliste = json_decode(file_get_contents('../kunden.json'), TRUE);
54)         foreach ($kundenliste as $k) {
55)                 foreach ($k['kontakt'] as $kon) {
56)                         if ($kon['wert'] == $number) {
57)                                 return $k;
58)                         }
59)                 }
60)         }
61)         */
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 4 years ago

62) }
63) 
Bernd Wurst Auswahl, ob per E-Mail oder...

Bernd Wurst authored 1 month ago

64) function kunde_erste_kontakte($customerno) {
65)     $ret = api_call('GET', 'customers/'.(int) $customerno);
66)     if ($ret['status_code'] >= 400) {
67)         // Fehler. Belästige den Kunden nicht damit
68)         return [];
69)     }
70)     $ret = $ret['data'];
71)     $kontakte = [];
72)     if (isset($ret['phone']) && str_starts_with($ret['phone'], '+491')) {
73)         $kontakte['mobil'] = $ret['phone'];
74)     }
75)     if (isset($ret['email']) && $ret['email']) {
76)         $kontakte['email'] = $ret['email'];
77)     }
78)     foreach ($ret['contacts'] as $c) {
79)         if (!isset($kontakte['mobil']) && isset($c['phone']) && str_starts_with($c['phone'], '+491')) {
80)             $kontakte['mobil'] = $c['phone'];
81)         }
82)         if (!isset($kontakte['email']) && isset($c['email']) && $c['email']) {
83)             $kontakte['email'] = $c['email'];
84)         }
85)     }
86)     return $kontakte;
87) }
88) 
89) 
Bernd Wurst frage E-Mail-Adresse ab

Bernd Wurst authored 1 year ago

90) function kunde_hat_email($customerno) {
91)     $ret = api_call('GET', 'customers/'.(int) $customerno);
92)     if ($ret['status_code'] >= 400) {
93)         // Fehler. Belästige den Kunden nicht damit
94)         return true;
95)     }
96)     $ret = $ret['data'];
97)     if (isset($ret['email']) && $ret['email']) {
98)         return true;
99)     }
100)     foreach ($ret['contacts'] as $c) {
101)         if (isset($c['email']) && $c['email']) {
102)             return true;
103)         }
104)     }
105)     return false;
106) }
107) 
108) 
109) 
110) function update_kunde($customerno, $daten) {
111)     $ret = api_call('GET', 'customers/'.(int) $customerno);
112)     if ($ret['status_code'] >= 400) {
113)         // Fehler. Erstelle Neukunde
114)         erstelle_kunde($daten);
115)         return;
116)     }
117)     $customer = $ret['data'];
118) 
119)     foreach ($daten as $field => $value) {
120)         if ($value) {
121)             $customer[$field] = $value;
122)         }
123)     }
124) 
Bernd Wurst Bindestrich vergessen

Bernd Wurst authored 1 year ago

125)     $filename = '../data/'.date('Y').'/'.time().'-kunde-'.$customerno.'.json';
Bernd Wurst frage E-Mail-Adresse ab

Bernd Wurst authored 1 year ago

126)     @file_put_contents($filename, json_encode($customer));
127)     $ret = api_call('PUT', 'customers/'.(int) $customerno, $customer);
128)     if ($ret['status_code'] >= 400) {
129)         foreach ($ret['data']['validation_errors'] as $item) {
130)             $_SESSION['warnings'][] = $item['key'].': '.$item['message'];
131)         }
132)         return null;
133)     }
134)     $ret = $ret['data'];
135)     if (isset($ret['id'])) {
136)         return $ret['id'];
137)     } else {
138)         return null;
139)     }
140) }
141) 
142) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

143) function erstelle_kunde($daten) {
144)     $json = [
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 1 year ago

145)         "firstname" => $daten['fname'] ?: null,
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

146)         "lastname" => $daten['lname'],
147)         "phone" => format_number_api($daten['phone']),
Bernd Wurst frage E-Mail-Adresse ab

Bernd Wurst authored 1 year ago

148)         "email" => $daten['email'] ?: null,
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 1 year ago

149)         "street" => $daten['address'] ?: null,
150)         "zip" => $daten['zip'] ?: null,
151)         "city" => $daten['city'] ?: null,
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

152)         "contacts" => []];
Bernd Wurst time() am Beginn der Datein...

Bernd Wurst authored 1 year ago

153)     $filename = '../data/'.date('Y').'/'.time().'-neukunde.json';
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 1 year ago

154)     @file_put_contents($filename, json_encode($json));
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

155)     $ret = api_call('POST', 'customers', $json);
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 1 year ago

156)     if ($ret['status_code'] >= 400) {
157)         foreach ($ret['data']['validation_errors'] as $item) {
Bernd Wurst Fange ungültige Telefonnumm...

Bernd Wurst authored 1 year ago

158)             $_SESSION['warnings'][] = $item['key'].': '.$item['message'];
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 1 year ago

159)         }
160)         return null;
161)     }
162)     $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

163)     if (isset($ret['id'])) {
164)         return $ret['id'];
165)     } else {
166)         return null;
167)     }
168) }
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 4 years ago

169) 
Bernd Wurst Auswahl, ob per E-Mail oder...

Bernd Wurst authored 1 month ago

170) require_once(__DIR__.'/../vendor/autoload.php');