master
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

1) <?php
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 3 years ago

3) 
4) function suche_kunde($name, $number) {
5)         global $content;
6)         if (! $number) {
7)             return NULL;
8)         }
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

10)         if ($ret['status_code'] >= 400) {
11)             foreach ($ret['data']['validation_errors'] as $item) {
12)                 $_SESSION['warning'][] = $item['message'];
13)             }
14)             return null;
15)         }
16)         $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

17)         if (count($ret) > 0) {
18)             $name = strtolower($name);
19)             foreach ($ret as $item) {
20)                 $cust = $item['customer'];
21)                 if ($name == strtolower($cust['lastname']) ||
22)                     $name == strtolower($cust['firstname']) ||
Bernd Wurst Erlaube nachname vorname

Bernd Wurst authored 7 months ago

23)                     $name == strtolower($cust['firstname'] .' '. $cust['lastname']) ||
24)                     $name == strtolower($cust['lastname'] .' '. $cust['firstname'])
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

25)                     ) {
26)                     return $cust;
27)                 }
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

28)             }
29)         }
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

30)         return null;
31) 
32)         /*
33)         $kundenliste = json_decode(file_get_contents('../kunden.json'), TRUE);
34)         foreach ($kundenliste as $k) {
35)                 foreach ($k['kontakt'] as $kon) {
36)                         if ($kon['wert'] == $number) {
37)                                 return $k;
38)                         }
39)                 }
40)         }
41)         */
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

42) }
43) 
Bernd Wurst frage E-Mail-Adresse ab

Bernd Wurst authored 6 months ago

44) function kunde_hat_email($customerno) {
45)     $ret = api_call('GET', 'customers/'.(int) $customerno);
46)     if ($ret['status_code'] >= 400) {
47)         // Fehler. Belästige den Kunden nicht damit
48)         return true;
49)     }
50)     $ret = $ret['data'];
51)     if (isset($ret['email']) && $ret['email']) {
52)         return true;
53)     }
54)     foreach ($ret['contacts'] as $c) {
55)         if (isset($c['email']) && $c['email']) {
56)             return true;
57)         }
58)     }
59)     return false;
60) }
61) 
62) 
63) 
64) function update_kunde($customerno, $daten) {
65)     $ret = api_call('GET', 'customers/'.(int) $customerno);
66)     if ($ret['status_code'] >= 400) {
67)         // Fehler. Erstelle Neukunde
68)         erstelle_kunde($daten);
69)         return;
70)     }
71)     $customer = $ret['data'];
72) 
73)     foreach ($daten as $field => $value) {
74)         if ($value) {
75)             $customer[$field] = $value;
76)         }
77)     }
78) 
Bernd Wurst Bindestrich vergessen

Bernd Wurst authored 5 months ago

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

Bernd Wurst authored 6 months ago

80)     @file_put_contents($filename, json_encode($customer));
81)     $ret = api_call('PUT', 'customers/'.(int) $customerno, $customer);
82)     if ($ret['status_code'] >= 400) {
83)         foreach ($ret['data']['validation_errors'] as $item) {
84)             $_SESSION['warnings'][] = $item['key'].': '.$item['message'];
85)         }
86)         return null;
87)     }
88)     $ret = $ret['data'];
89)     if (isset($ret['id'])) {
90)         return $ret['id'];
91)     } else {
92)         return null;
93)     }
94) }
95) 
96) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 6 months ago

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

Bernd Wurst authored 7 months ago

103)         "street" => $daten['address'] ?: null,
104)         "zip" => $daten['zip'] ?: null,
105)         "city" => $daten['city'] ?: null,
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 5 months ago

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

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

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

Bernd Wurst authored 7 months ago

113)         }
114)         return null;
115)     }
116)     $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 7 months ago

117)     if (isset($ret['id'])) {
118)         return $ret['id'];
119)     } else {
120)         return null;
121)     }
122) }