bcc6eb8e880fdf035d3971cb67ad88745c77b2f8
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 frage E-Mail-Adresse ab

Bernd Wurst authored 1 year ago

64) function kunde_hat_email($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 true;
69)     }
70)     $ret = $ret['data'];
71)     if (isset($ret['email']) && $ret['email']) {
72)         return true;
73)     }
74)     foreach ($ret['contacts'] as $c) {
75)         if (isset($c['email']) && $c['email']) {
76)             return true;
77)         }
78)     }
79)     return false;
80) }
81) 
82) 
83) 
84) function update_kunde($customerno, $daten) {
85)     $ret = api_call('GET', 'customers/'.(int) $customerno);
86)     if ($ret['status_code'] >= 400) {
87)         // Fehler. Erstelle Neukunde
88)         erstelle_kunde($daten);
89)         return;
90)     }
91)     $customer = $ret['data'];
92) 
93)     foreach ($daten as $field => $value) {
94)         if ($value) {
95)             $customer[$field] = $value;
96)         }
97)     }
98) 
Bernd Wurst Bindestrich vergessen

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

100)     @file_put_contents($filename, json_encode($customer));
101)     $ret = api_call('PUT', 'customers/'.(int) $customerno, $customer);
102)     if ($ret['status_code'] >= 400) {
103)         foreach ($ret['data']['validation_errors'] as $item) {
104)             $_SESSION['warnings'][] = $item['key'].': '.$item['message'];
105)         }
106)         return null;
107)     }
108)     $ret = $ret['data'];
109)     if (isset($ret['id'])) {
110)         return $ret['id'];
111)     } else {
112)         return null;
113)     }
114) }
115) 
116) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

123)         "street" => $daten['address'] ?: null,
124)         "zip" => $daten['zip'] ?: null,
125)         "city" => $daten['city'] ?: null,
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

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

Bernd Wurst authored 1 year ago

133)         }
134)         return null;
135)     }
136)     $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 1 year ago

137)     if (isset($ret['id'])) {
138)         return $ret['id'];
139)     } else {
140)         return null;
141)     }
142) }