Browse code

Kundendaten ändern, Gitterbox hinzufügen / entfernen

Bernd Wurst authored on15/06/2020 20:45:48
Showing6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,34 @@
1
+<?php
2
+require_once 'lib/api.php';
3
+require_once 'lib/tools.php';
4
+// some sort of limit?!
5
+session_start();
6
+
7
+$ret = '';
8
+$data = array("kunde" => array(), "uuid" => '');
9
+
10
+$fields = array("kundennr", "firma", "vorname", "nachname", "adresse", "plz", "ort");
11
+foreach ($fields as $key) {
12
+    if (isset($_GET[$key])) {
13
+        $data['kunde'][$key] = $_GET[$key];
14
+    }
15
+}
16
+if (isset($_GET['telefon'])) {
17
+    $data['kunde']['kontakt'] = array();
18
+    $data['kunde']['kontakt'][] = array(
19
+        "typ" => "telefon",
20
+        "wert" => $_GET['telefon']);
21
+}
22
+
23
+$ret = api_call('kunde/aendern', $data);
24
+
25
+if (!isset($ret['kunde'])) {
26
+    return;
27
+}
28
+$ret['kunde']['html'] = adresse($ret['kunde'], 'kundendaten');
29
+
30
+header('Content-Type: application/json');
31
+echo json_encode($ret['kunde']);
32
+
33
+
34
+
... ...
@@ -1,34 +1,63 @@
1 1
 <?php
2 2
 require_once 'lib/api.php';
3
+require_once 'lib/tools.php';
3 4
 // some sort of limit?!
4 5
 session_start();
5 6
 
6
-$ret = '';
7
-$data = array();
7
+$data = array("handle" => $_GET['handle']);
8 8
 
9
-if (isset($_GET['handle'])) {
10
-    $data['handle'] = htmlspecialchars($_GET['handle']);
9
+$ret = api_call('vorgang/lesen', $data);
10
+
11
+if (!isset($ret['vorgang'])) {
12
+    echo 'error!';
13
+    die();
11 14
 }
12 15
 
13
-if ($data) {
14
-    $ret = api_call('vorgang/lesen', $data);
16
+$vorgang = $ret['vorgang'];
17
+
18
+switch ($_GET['action']) {
19
+    case 'delete_gitterbox':
20
+        if (isset($_GET['id'])) {
21
+            $id = $_GET['id'];
22
+            foreach ($vorgang['bestellung'][0]['gitterbox'] as $key => $item) {
23
+                if ($item['id'] == $id) {
24
+                    unset($vorgang['bestellung'][0]['gitterbox'][$key]);
25
+                    break;
26
+                }
27
+            }
28
+        } else {
29
+            array_shift($vorgang['bestellung'][0]['gitterbox']);
30
+        }
31
+        break;
32
+    case 'delete_anhaenger':
33
+        $kennz = $_GET['kennz'];
34
+        foreach ($vorgang['bestellung'][0]['anhaenger'] as $key => $item) {
35
+            if ($item['kennz'] == $kennz) {
36
+                unset($vorgang['bestellung'][0]['anhaenger'][$key]);
37
+                break;
38
+            }
39
+        }
40
+        break;
41
+    case 'add_gitterbox':
42
+        $id = (isset($_GET['id']) ? $_GET['id'] : null);
43
+        $vorgang['bestellung'][0]['gitterbox'][] = array("id" => $id);
44
+        break;
45
+    case 'add_anhaenger':
46
+        $kennz = (isset($_GET['kennz']) ? $_GET['kennz'] : null);
47
+        $vorgang['bestellung'][0]['anhaenger'][] = array("kennz" => $kennz);
48
+        break;
15 49
 }
16 50
 
17
-$auftrag = $ret['vorgang'];
18 51
 
19
-$changes = $_GET;
20
-unset($changes['handle']);
21 52
 
22
-foreach ($changes as $path => $value) {
23
-    $current =& $auftrag;
24
-    // setze Referenz $current Schritt für Schritt auf $array['item_1']['item_2'][...]['item_n']
25
-    foreach(explode('/', $path) as $key) {
26
-        $current =& $current[$key];
27
-    }
28
-    // belege dieses Array-Element mit $value
29
-    $current = $value;
53
+$ret = api_call('vorgang/aendern', $vorgang);
54
+
55
+if (!isset($ret['vorgang'])) {
56
+    return;
30 57
 }
31 58
 
32
-api_call('vorgang/aendern', $auftrag);
59
+header('Content-Type: application/json');
60
+echo json_encode($ret['vorgang']);
61
+
33 62
 
34 63
 
... ...
@@ -83,12 +83,90 @@ function telefonnummer_fuer_auftrag() {
83 83
     auftrag_telefon_speichern()
84 84
 }
85 85
 
86
+function gitterbox_loeschen_callback( gb ) {
87
+    return function() {
88
+        $.getJSON('ajax_vorgang_aendern.php', {"handle": $('#handle').val(), "action": "delete_gitterbox", "id": gb }, callback_obstlieferung);
89
+    }
90
+}
91
+
92
+
93
+function callback_obstlieferung( vorgang ) {
94
+    $(".lieferart .gitterbox").remove();
95
+    $(".lieferart .anhaenger").remove();
96
+    for (let idx in vorgang['bestellung'][0]['gitterbox']) {
97
+        gb = vorgang['bestellung'][0]['gitterbox'][idx];
98
+        var img = '<img class="gitterbox" src="/assets/images/gitterbox.png"><br>';
99
+        if (gb['id']) {
100
+            img += 'GB #'+gb['id'];
101
+        } else {
102
+            img += 'Gitterbox';
103
+        }
104
+        $(".lieferart").prepend('<a href="#" class="gitterbox">'+img+'</a>');
105
+    }
106
+    for (let idx in vorgang['bestellung'][0]['anhaenger']) {
107
+        anh = vorgang['bestellung'][0]['anhaenger'][idx];
108
+        var img = '<img class="anhaenger" src="/assets/images/anhaenger.png"><br>';
109
+        if (anh['kennz']) {
110
+            img += ' <strong>'+anh['kennz']+'</strong> ';
111
+        } else {
112
+            img += ' <em>Anhänger</em>';
113
+        }
114
+        $(".lieferart").prepend('<a href="#" class="anhaenger">'+img+'</a>');
115
+    }
116
+    $('a.anhaenger').off("click");
117
+    $('a.gitterbox').off("click");
118
+    $('a.anhaenger').click(anhaenger_loeschen);
119
+    $('a.gitterbox').click(gitterbox_loeschen);
120
+}
121
+
122
+function anhaenger_loeschen_callback( kennz ) {
123
+    return function() {
124
+        $.getJSON('ajax_vorgang_aendern.php', {"handle": $('#handle').val(), "action": "delete_anhaenger", "kennz": kennz}, callback_obstlieferung);
125
+    }
126
+}
127
+
86 128
 
87
-function gitterbox_loeschen() {
129
+function gitterbox_loeschen( event ) {
130
+    modal_confirmation("Gitterbox löschen?", "Soll eine Gitterbox gelöscht werden?", gitterbox_loeschen_callback(null));
131
+    event.preventDefault();
132
+}
133
+
134
+function anhaenger_loeschen() {
135
+    kennz = $(this).find("strong").text();
136
+    modal_confirmation("Anhaenger löschen?", "Soll der Anhänger <strong>"+kennz+"</strong> gelöscht werden?", anhaenger_loeschen_callback(kennz));
137
+    event.preventDefault();
138
+    
139
+}
140
+
141
+function callback_gitterbox_neu( vorgang ) 
142
+{
143
+    $('#gitterbox-neu-dialog').modal('hide');
144
+    callback_obstlieferung(vorgang);
145
+}
146
+
147
+function gitterbox_neu() {
148
+    $('#gitterbox-neu-dialog').modal('show');
149
+    $('#gitterbox-neu-gb').off();
150
+    $('#gitterbox-neu-gb').click(function () {
151
+        id = $('#gitterbox-neu-id').val();
152
+        if (id == '') {
153
+            id = null;
154
+        }
155
+        $.getJSON('ajax_vorgang_aendern.php', {"handle": $('#handle').val(), "action": "add_gitterbox", "id": id }, callback_gitterbox_neu);
156
+    });
157
+    $('#gitterbox-neu-anh').off();
158
+    $('#gitterbox-neu-anh').click(function () {
159
+        kennz = $('#gitterbox_neu_kennz').val();
160
+        if (kennz == '') {
161
+            kennz = null;
162
+        }
163
+        $.getJSON('ajax_vorgang_aendern.php', {"handle": $('#handle').val(), "action": "add_anhaenger", "kennz": kennz }, callback_gitterbox_neu);
164
+    });
88 165
 }
89 166
 
90 167
 
91 168
 $(document).ready(function () {
169
+    // Kundendaten
92 170
     $('#kundendaten_kundennr').change(function () {
93 171
         if ($('#kundendaten_kundennr').val() != '') {
94 172
             $.getJSON('ajax_kundendaten.php', {"kundennr": $('#kundendaten_kundennr').val()}, lade_kundendaten_callback);
... ...
@@ -100,8 +178,14 @@ $(document).ready(function () {
100 178
     $('#telefon').change(auftrag_telefon_speichern);
101 179
     $('#auftragsdaten_telefon').click(telefonnummer_fuer_auftrag);
102 180
     $('#btn_kunde_suchen').click( kunde_suchen );
181
+    $('#btn_kunde_aendern').click( modal_kunde_aendern );
103 182
     if ($('#kundendaten_kundennr').val() != '') {
104 183
         $.getJSON('ajax_kundendaten.php', {"kundennr": $('#kundendaten_kundennr').val()}, lade_kundendaten_callback);
105 184
     }
106 185
     modal_kundensuche();
186
+
187
+    // Auftrag
188
+    $('a.anhaenger').click(anhaenger_loeschen)
189
+    $('a.gitterbox').click(gitterbox_loeschen);
190
+    $('a.gitterbox_neu').click(gitterbox_neu);
107 191
 });
... ...
@@ -53,7 +53,7 @@ function kundensuche_callback( data ) {
53 53
 
54 54
 function kundeerstellen_callback( data ) {
55 55
     if (data['kundennr'] != '') {
56
-        $('#kundendaten_kundennr').val(kundennr);
56
+        $('#kundendaten_kundennr').val(data['kundennr']);
57 57
         $('#kundendaten_kundennr').change();
58 58
         $('#kundeerstellen-dialog').modal('hide');
59 59
     }
... ...
@@ -104,6 +104,68 @@ function modal_kundensuche() {
104 104
 }
105 105
 
106 106
 
107
+function kunde_aendern_callback( data ) {
108
+    if (data['kundennr'] != '') {
109
+        $('#kundendaten_kundennr').val(data['kundennr']);
110
+        $('#kundendaten_kundennr').change();
111
+        $('#kundeaendern-dialog').modal('hide');
112
+    }
113
+}
114
+
115
+
116
+function kunde_aendern_fillfields( data ) {
117
+    $('#kundeaendern_kundennr').val(data['kundennr']);
118
+    $('#kundeaendern_firma').val(data['firma']);
119
+    $('#kundeaendern_vorname').val(data['vorname']);
120
+    $('#kundeaendern_nachname').val(data['nachname']);
121
+    $('#kundeaendern_adresse').val(data['adresse']);
122
+    $('#kundeaendern_plz').val(data['plz']);
123
+    $('#kundeaendern_ort').val(data['ort']);
124
+    $('#kundeaendern_telefon').val(data['kontakt'][0]['wert']);
125
+}
126
+
127
+
128
+function modal_kunde_aendern() {
129
+    // #kundendaten_kundennr ist immer ein Formularfeld
130
+    $('#kundenaendern_kundennr').val($('#kundendaten_kundennr').val());
131
+    $.getJSON('ajax_kundendaten.php', {"kundennr": $('#kundendaten_kundennr').val()}, kunde_aendern_fillfields);
132
+    $('#kundeaendern-dialog').modal('show');
133
+    $('#kundeaendern_submit').off("click");
134
+    $('#kundeaendern_submit').click(function () {
135
+        // speichern
136
+        $.getJSON('ajax_kunde_aendern.php', {
137
+            "kundennr": $('#kundeaendern_kundennr').val(),
138
+            "firma": $('#kundeaendern_firma').val(),
139
+            "vorname": $('#kundeaendern_vorname').val(),
140
+            "nachname": $('#kundeaendern_nachname').val(),
141
+            "adresse": $('#kundeaendern_adresse').val(),
142
+            "plz": $('#kundeaendern_plz').val(),
143
+            "ort": $('#kundeaendern_ort').val(),
144
+            "telefon": $('#kundeaendern_telefon').val()
145
+            }, kunde_aendern_callback);
146
+    });
147
+
148
+}
149
+
150
+function modal_confirmation_okcallback( cb ) 
151
+{
152
+    return function () {
153
+        $('#confirmation-dialog').modal('hide');
154
+        cb();
155
+    };
156
+}
157
+
158
+
159
+function modal_confirmation( title, body, callback_ok )
160
+{
161
+    $('#confirmation-dialog .modal-title').text(title);
162
+    $('#confirmation-dialog .modal-body').html(body);
163
+    $('#confirmation-ok').off("click");
164
+    $('#confirmation-ok').on("click", modal_confirmation_okcallback(callback_ok));
165
+    $('#confirmation-dialog').modal('show');
166
+}
167
+
168
+
107 169
 $(document).ready( function () {
108 170
     
109 171
 });
... ...
@@ -42,9 +42,9 @@ $content .= adresse($a['kundendaten'], 'auftragsdaten');
42 42
 $content .= '</p>';
43 43
 $content .= '</div>
44 44
 <div class="kundendaten_kunde">
45
-<p><em>Aus der Datenbank</em></p>
45
+<p><em>Kundendaten:</em></p>
46 46
 <p id="kundendaten_kundenadresse">---</p>';
47
-$content .= '</td><td><input type="hidden" name="kundendaten_kundennr" id="kundendaten_kundennr" value="'.(isset($a['kundennr']) ? $a['kundennr'] : '').'"><button class="btn btn-secondary" id="btn_kunde_suchen">Kunde suchen</button>';
47
+$content .= '</td><td><input type="hidden" name="kundendaten_kundennr" id="kundendaten_kundennr" value="'.(isset($a['kundennr']) ? $a['kundennr'] : '').'"><button class="btn btn-secondary" id="btn_kunde_suchen">Kunde suchen</button> <button class="btn btn-outline-secondary" id="btn_kunde_aendern">Kunde ändern</button> ';
48 48
 $content .= '</div>';
49 49
 
50 50
 $content .= '</td></tr></table>';
... ...
@@ -132,8 +132,35 @@ $content .= '<div class="auftrag_bestaetigen"><button class="btn btn-primary">Au
132 132
 <button class="btn btn-secondary">Auftrag annehmen und sofort verarbeiten</button></div>';
133 133
 $content .= '</form>';
134 134
 
135
+$content .= '
136
+    <div class="modal fade" id="gitterbox-neu-dialog" tabindex="-1" role="dialog" aria-labelledby="Gitterbox" aria-hidden="true">
137
+        <div class="modal-dialog">
138
+            <div class="modal-content">
139
+                <div class="modal-header">
140
+                    <h4 class="modal-title">Neue Gitterbox erfassen</h4>
141
+                </div>
142
+
143
+                <div class="modal-body">
144
+                <p>ID-Nummer: <input type="text" name="gb" id="gitterbox-neu-id" value=""></p>
145
+                <p><button class="btn btn-primary" id="gitterbox-neu-gb">Gitterbox hinzufügen</p>
146
+                </div>
147
+
148
+                <div class="modal-body">
149
+                <p>Kennzeichen: <input type="text" name="kennz" id="gitterbox-neu-kennz" value=""></p>
150
+                <p><button class="btn btn-primary" id="gitterbox-neu-anh">Anhänger hinzufügen</p>
151
+                </div>
152
+
153
+                <div class="modal-footer">
154
+                    <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Abbrechen</button>
155
+                </div>
156
+            </div>
157
+        </div>
158
+    </div>
159
+';
135 160
 
136 161
 $content .= modal_kundensuche($a['kundendaten']);
162
+$content .= modal_kunde_aendern();
163
+$content .= modal_confirmation();
137 164
 
138 165
 
139 166
 include "template.php";
... ...
@@ -54,11 +54,42 @@ function modal_kundensuche($k = null) {
54 54
                     </table>
55 55
                 </div>
56 56
 
57
-                <div class="modal-body" id="kundensuche_ergebnisse">
57
+                <div class="modal-footer">
58
+                    <button type="button" class="btn btn-primary" id="kundeerstellen_submit">Kunde anlegen</button>
59
+                    <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Abbrechen</button>
60
+                </div>
61
+            </div>
62
+        </div>
63
+    </div>
64
+';
65
+    return $ret;
66
+}
67
+
68
+
69
+function modal_kunde_aendern() {
70
+    $ret = '
71
+        <div class="modal fade" id="kundeaendern-dialog" tabindex="-1" role="dialog" aria-labelledby="Kundendaten ändern" aria-hidden="true">
72
+        <div class="modal-dialog">
73
+            <div class="modal-content">
74
+                <div class="modal-header">
75
+                    <h4 class="modal-title">Kundendaten ändern</h4>
76
+                </div>
77
+
78
+                <div class="modal-body">
79
+                    <input type="hidden" name="kundennr" id="kundeaendern_kundennr" value="">
80
+                    <table>
81
+                    <tr><td>Firmenname:</td><td><input type="text" name="kundeaendern_firma" id="kundeaendern_firma" value=""</td></tr>
82
+                    <tr><td>Vorname:</td><td><input type="text" name="kundeaendern_vorname" id="kundeaendern_vorname" value=""</td></tr>
83
+                    <tr><td>Nachname:</td><td><input type="text" name="kundeaendern_nachname" id="kundeaendern_nachname" value=""</td></tr>
84
+                    <tr><td>Adresse:</td><td><input type="text" name="kundeaendern_adresse" id="kundeaendern_adresse" value=""</td></tr>
85
+                    <tr><td>PLZ:</td><td><input type="text" name="kundeaendern_plz" id="kundeaendern_plz" value=""</td></tr>
86
+                    <tr><td>Ort:</td><td><input type="text" name="kundeaendern_ort" id="kundeaendern_ort" value=""</td></tr>
87
+                    <tr><td>Telefon:</td><td><input type="text" name="kundeaendern_telefon" id="kundeaendern_telefon" value=""</td></tr>
88
+                    </table>
58 89
                 </div>
59 90
 
60 91
                 <div class="modal-footer">
61
-                    <button type="button" class="btn btn-primary" id="kundeerstellen_submit">Kunde anlegen</button>
92
+                    <button type="button" class="btn btn-primary" id="kundeaendern_submit">Daten ändern</button>
62 93
                     <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Abbrechen</button>
63 94
                 </div>
64 95
             </div>
... ...
@@ -68,5 +99,27 @@ function modal_kundensuche($k = null) {
68 99
     return $ret;
69 100
 }
70 101
 
102
+function modal_confirmation() {
103
+    $ret = '
104
+        <div class="modal fade" id="confirmation-dialog" tabindex="-1" role="dialog" aria-labelledby="Sicher?" aria-hidden="true">
105
+        <div class="modal-dialog">
106
+            <div class="modal-content">
107
+                <div class="modal-header">
108
+                    <h4 class="modal-title">Sicher?</h4>
109
+                </div>
110
+
111
+                <div class="modal-body">
112
+                </div>
113
+
114
+                <div class="modal-footer">
115
+                    <button type="button" class="btn btn-danger" id="confirmation-ok">Löschen</button>
116
+                    <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Abbrechen</button>
117
+                </div>
118
+            </div>
119
+        </div>
120
+    </div>
121
+';
122
+    return $ret;
123
+}
71 124
 
72 125