瀏覽代碼

- Kunden auf aktuelles Datum gefiltert
- Bearbeiten-Seite ohne Funktion
- Aktualisieren

Robert Bedner 10 年之前
父節點
當前提交
c3b129b927
共有 6 個文件被更改,包括 506 次插入27 次删除
  1. 40 0
      app/db.php
  2. 98 0
      app/import.php
  3. 1 0
      app/index.html
  4. 3 7
      app/scripts/app.js
  5. 102 14
      app/scripts/controllers/overview.js
  6. 262 6
      app/views/overview.html

+ 40 - 0
app/db.php

@@ -0,0 +1,40 @@
+<?php
+$dbh = new PDO("mysql:host=localhost;dbname=tasks", "root", "gc01mysql");
+$dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
+
+if (isset($_GET['kunde']) && isset($_GET['datum'])) {
+	$q = $dbh->query("SELECT * FROM statusmail WHERE kunde = '{$_GET['kunde']}' AND datum = '{$_GET['datum']}' LIMIT 1");
+	$result = $q->fetch(PDO::FETCH_ASSOC);
+	$result['fehlerbericht'] = str_replace("\\", "\\\\", str_replace("\r\"", "\"", str_replace("\r\n", "", $result['fehlerbericht'])));
+	$result['fehlerbericht'] = json_decode($result['fehlerbericht'], true);
+
+} else if (isset($_GET['kunden'])) {
+	$q = $dbh->query("SELECT * FROM kunden");
+	$result = $q->fetchAll(PDO::FETCH_ASSOC);
+} else {
+	$date = date("Y-m");
+
+	$q = $dbh->query("SELECT a.datum, k.kunde, left(k.system, 1) as system, a.bundesland, a.feiertag, k.start_soll, k.ende_soll, s.start, s.ende, s.anzahl, s.bearbeitet, s.benutzer, s.kommentar,
+							if(s.anzahl is null or s.anzahl > 0, 1, 0) as fehler,
+							timediff(k.ende_soll, k.start_soll) as dauer,
+							timediff(s.ende, k.ende_soll) as abweichung,
+							case
+							 when woche = 'Mo-Fr' then mofr
+							 when woche = 'Mo-Sa' then mosa
+							 when woche = 'Mo-So' then moso
+							 when woche = 'Di-So' then diso
+							 else 1
+							end * if(anzahl is null and now() > concat(a.datum, ' ', k.ende_soll), 1, 0) as fehlt
+						FROM arbeitstage a
+						INNER JOIN kunden k USING (bundesland)
+						LEFT JOIN statusmail s USING (datum, kunde)
+						WHERE datum LIKE '{$date}%' AND k.erster_status <= a.datum AND a.datum <= now()
+						AND k.aktiv = 1
+						ORDER BY a.datum, k.ende_soll");
+	$result = $q->fetchAll(PDO::FETCH_ASSOC);
+}
+
+header('Access-Control-Allow-Origin: *');
+header('Cache-Control: no-cache, must-revalidate');
+header('Content-type: application/json');
+echo json_encode($result);

+ 98 - 0
app/import.php

@@ -0,0 +1,98 @@
+<?php
+header('Access-Control-Allow-Origin: *');
+header('Cache-Control: no-cache, must-revalidate');
+header('Content-type: application/json');
+
+$dbh = new PDO("mysql:host=localhost;dbname=tasks", "root", "gc01mysql");
+$dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
+
+$server = "{imap.1und1.de:993/imap/ssl}INBOX";
+$user = "status@global-cube.de";
+$passwd = "gc01smtp";
+
+$q = $dbh->query("SELECT kunde FROM kunden");
+$customers = $q->fetchAll(PDO::FETCH_COLUMN, 0);
+
+$mbox = imap_open($server, $user, $passwd) or die("Could not open Mailbox - try again later!");
+$message_count = imap_num_msg($mbox);
+
+$result = array();
+
+for ($m = 1; $m <= $message_count; ++$m) {
+	$header = imap_headerinfo($mbox, $m);
+	$rec = explode(";", $header->Subject);
+	if (count($rec) < 3) continue;
+
+	$date = date("Y-m-d", strtotime($header->MailDate));
+	$result[] = $date . " " . $rec[2] . " - " . $rec[0];
+
+	$body = trim(imap_fetchbody($mbox, $m, '1'));
+	if (substr($body, 0, 4) == "--b2") {
+		$body = "";
+	}
+	array_push($rec, $body);
+
+
+
+	$structure = imap_fetchstructure($mbox, $m);
+	$attachments = array();
+	if (isset($structure->parts) && count($structure->parts)) {
+
+		for ($i = 0; $i < count($structure->parts); $i++) {
+
+			$attachments[$i] = array(
+				'is_attachment' => false,
+				'filename' => '',
+				'name' => '',
+				'attachment' => ''
+			);
+
+			if ($structure->parts[$i]->ifdparameters) {
+				foreach ($structure->parts[$i]->dparameters as $object) {
+					if (strtolower($object->attribute) == 'filename') {
+						$attachments[$i]['is_attachment'] = true;
+						$attachments[$i]['filename'] = $object->value;
+					}
+				}
+			}
+
+			if ($structure->parts[$i]->ifparameters) {
+				foreach ($structure->parts[$i]->parameters as $object) {
+					if (strtolower($object->attribute) == 'name') {
+						$attachments[$i]['is_attachment'] = true;
+						$attachments[$i]['name'] = $object->value;
+					}
+				}
+			}
+
+			if ($attachments[$i]['is_attachment']) {
+				$attachments[$i]['attachment'] = imap_fetchbody($mbox, $m, $i + 1);
+				if ($structure->parts[$i]->encoding == 3) { // 3 = BASE64
+					$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
+				} elseif ($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
+					$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
+				}
+			}
+		}
+	}
+
+	$a = "";
+	foreach ($attachments as $key => $attachment) {
+		if ($attachment['is_attachment'] && preg_match("/\.bat\.log/", $attachment['filename'])) {
+			$a .= $attachment['attachment'];
+		}
+	}
+	array_push($rec, addslashes($a));
+	$dbh->query("INSERT INTO statusmail (kunde, start, ende, datum, anzahl, fehlerbericht, logdatei) VALUES ('" . implode("','", $rec) . "')");
+
+	imap_delete($mbox, $m);
+
+	if (!in_array($rec[0], $customers)) {
+		$dbh->query("INSERT INTO kunden (kunde, start_soll, ende_soll, erster_status) VALUES ('{$rec[0]}', '{$rec[1]}', '{$rec[2]}', '{$rec[3]}')");
+		array_push($customers, $rec[0]);
+	}
+}
+imap_expunge($mbox);
+imap_close($mbox);
+
+echo json_encode($result);

+ 1 - 0
app/index.html

@@ -101,6 +101,7 @@
     <script src="bower_components/angular-touch/angular-touch.js"></script>
     <script src="bower_components/angular-route/angular-route.js"></script>
     <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
+    <script src="bower_components/moment/moment.js"></script>
     <script src="bower_components/underscore/underscore.js"></script>
     <!-- endbower -->
     <!-- endbuild -->

+ 3 - 7
app/scripts/app.js

@@ -2,14 +2,14 @@
 
 /**
  * @ngdoc overview
- * @name kasseApp
+ * @name fehlerberichtApp
  * @description
- * # kasseApp
+ * # fehlerberichtApp
  *
  * Main module of the application.
  */
 angular
-    .module('kasseApp', [
+    .module('fehlerberichtApp', [
         'ngAnimate',
         'ngCookies',
         'ngResource',
@@ -20,10 +20,6 @@ angular
     .config(function ($routeProvider) {
         $routeProvider
             .when('/', {
-                templateUrl: 'views/main.html',
-                controller: 'MainCtrl'
-            })
-            .when('/overview', {
                 templateUrl: 'views/overview.html',
                 controller: 'OverviewCtrl'
             })

+ 102 - 14
app/scripts/controllers/overview.js

@@ -2,26 +2,114 @@
 
 /**
  * @ngdoc function
- * @name kasseApp.controller:AboutCtrl
+ * @name fehlerberichtApp.controller:AboutCtrl
  * @description
  * # AboutCtrl
- * Controller of the kasseApp
+ * Controller of the fehlerberichtApp
  */
-angular.module('kasseApp')
-    .controller('OverviewCtrl', function ($scope) {
-        $scope.Produkte = [ "btn-primary", "btn-info", "btn-darkgreen", "btn-success", "btn-warning" ];
+angular.module('fehlerberichtApp')
+    .controller('OverviewCtrl', function ($scope, $http) {
+        var webservice = 'http://rbs06/GlobalCube/Fehlerbericht/app/db.php?';
 
-        $scope.Bestellungen = JSON.parse(window.localStorage.getItem("OffeneBestellungen"));
+        $scope.info = [];
+        $scope.error = -1;
 
-        $("body").keypress(function (event) {
-            var key = event.which - 49;
-            if (key >= 0 && key < $scope.Bestellungen.length) {
-                $scope.removeItem(key);
-                console.log(key);
-            }
-        });
+        $scope.benutzer = window.localStorage.getItem("Benutzer");
+
+        $scope.overview = [];
+
+        $scope.datum = [];
+        $scope.kunden = [];
+
+        $scope.current = {
+            'kunde' : '',
+            'datum': '',
+            'fehler': {}
+        };
+
+        $scope.Filter = {
+            'datum': moment().format('YYYY-MM-DD'),
+            'kunde': '',
+            'fehler': '1'
+        };
 
         $scope.removeItem = function (index) {
             $scope.Bestellungen = $scope.Bestellungen.splice(index, 1);
         };
-    });
+
+        $scope.refresh = function () {
+            $http.get(webservice).success(function (data) {
+                $scope.overview = data;
+                $scope.datum = _.uniq(_.pluck(data, 'datum'));
+            });
+
+            $http.get(webservice + 'kunden=1').success(function (data) {
+                $scope.kunden = data;
+            });
+        };
+
+        $scope.importData = function () {
+            $http.get('http://rbs06/GlobalCube/Fehlerbericht/app/import.php').success(function (data) {
+                if (Array.isArray(data)) {
+                    $scope.info = data;
+                    if (data.length === 0) {
+                        $scope.error = -1;
+                    } else {
+                        $scope.error = 0;
+                        $scope.refresh();
+                    }
+                } else {
+                    $scope.info[0] = data;
+                    $scope.error = 1;
+                }
+            });
+        };
+
+        $scope.refresh();
+
+        $scope.minuten = function (t) {
+            var faktor, m, mins;
+            if (!t) {
+                return '';
+            }
+            faktor = 1;
+            if (t < '00:00:00') {
+                t = t.substring(1);
+                faktor = -1;
+            }
+            m = moment(t, 'HH:mm:ss');
+            mins = faktor * (m.minutes() + m.hours() * 60);
+            return mins + " Min.";
+        };
+
+        $scope.dateFormat = function (date) {
+            var d = moment(date);
+            if (d.isValid()) {
+                return moment(date).format('DD.MM.YYYY');
+            }
+            return date;
+        };
+
+        $scope.setCurrent = function (zeile) {
+            $scope.current.kunde = zeile.kunde;
+            $scope.current.datum = zeile.datum;
+
+            $http.get(webservice + 'kunde=' + zeile.kunde + '&datum=' + zeile.datum).success(function (data) {
+                $scope.current.fehler = data;
+                if (data.benutzer === '') {
+                    $scope.current.fehler.benutzer = $scope.benutzer;
+                }
+            });
+        };
+
+        $scope.saveUser = function (name) {
+            window.localStorage.setItem("Benutzer", name);
+            $scope.benutzer = name;
+        };
+
+        $scope.saveComments = function () {
+            $http.post(webservice + 'kunde=' + $scope.current.kunde + '&datum=' + $scope.current.datum, $scope.current.fehler).success(function (data) {
+                window.alert('Hat geklappt!');
+            });
+        };
+    });

+ 262 - 6
app/views/overview.html

@@ -1,9 +1,265 @@
-<div class="row" ng-keypress="removeItem($event.keyCode-49)">
-    <div class="col-md-4" ng-repeat="b in Bestellungen">
-        <button type="button" class="btn btn-lg btn-danger">{{$index+1}}</button><br/>
-        <button type="button" class="btn btn-lg btn-block btn-default">Bon Nr. {{b.Rechnung}}</button>
-        <button type="button" ng-repeat="pos in b.Bestellung" class="btn btn-lg btn-block {{Produkte[pos.Produkt]}}" >{{pos.Anzahl}}x {{pos.Bezeichnung}}</button>
-    </div>
+<button type="button" class="btn btn-info" ng-click="importData()">
+    <span class="glyphicon glyphicon-refresh"></span>
+</button>
+<br/><br/>
+<div class="alert alert-success" role="alert" ng-show="error > -1" ng-class="{'alert-danger': error == 1}">
+    Neu importiert:
+    <ul>
+        <li ng-repeat="opt in info">{{opt}}</li>
+    </ul>
+</div>
+
+<div class="well" ng-show="benutzer==null">
+    <label>Benutzer:
+        <input ng-model="benutzer2"/>
+    </label>
+    <button class="btn btn-default btn-sm" ng-click="saveUser(benutzer2)">Speichern</button>
+</div>
+
+<table class="table table-bordered table-striped">
+    <tr>
+        <th>Datum</th>
+        <th>Kunde</th>
+        <th>Start</th>
+        <th>Ende (Soll/Ist)</th>
+        <th>Abweichung</th>
+        <th>Fehler</th>
+    </tr>
+    <tr>
+        <td>
+            <div class="dropdown">
+                <a class="btn dropdown-toggle" role="button" data-toggle="dropdown">{{dateFormat(Filter.datum)||'alle'}}&nbsp;<b class="caret"></b></a>
+                <ul class="dropdown-menu" role="menu">
+                    <li><a ng-click="Filter.datum=''">alle</a></li>
+                    <li class="divider"></li>
+                    <li ng-repeat="opt in datum"><a ng-click="Filter.datum=opt">{{dateFormat(opt)}}</a></li>
+                </ul>
+            </div>
+        </td>
+        <td>
+            <div class="dropdown">
+                <a class="btn dropdown-toggle" role="button" data-toggle="dropdown">{{Filter.kunde||'alle'}}&nbsp;<b class="caret"></b></a>
+                <ul class="dropdown-menu" role="menu">
+                    <li><a ng-click="Filter.kunde=''">alle</a></li>
+                    <li class="divider"></li>
+                    <li ng-repeat="opt in kunden"><a ng-click="Filter.kunde=opt.kunde">{{opt.kunde}}</a></li>
+                </ul>
+            </div>
+        </td>
+        <td></td>
+        <td></td>
+        <td></td>
+        <td>
+            <div class="dropdown">
+                <a class="btn dropdown-toggle" role="button" data-toggle="dropdown">fehlerhafte&nbsp;<b class="caret"></b></a>
+                <ul class="dropdown-menu" role="menu">
+                    <li><a ng-click="Filter.fehler=''">alle</a></li>
+                    <li class="divider"></li>
+                    <li><a ng-click="Filter.fehler='1'">fehlerhafte</a></li>
+                    <li><a ng-click="Filter.fehler='0'">fehlerfreie</a></li>
+                </ul>
+            </div>
+        </td>
+    </tr>
+
+    <tr ng-repeat="zeile in overview | filter:Filter" ng-class="{'danger':zeile.kommentar==null}">
+        <td>{{dateFormat(zeile.datum)}}</td>
+        <td><span class="label label-danger label-{{zeile.system}}">{{zeile.system}}</span> {{zeile.kunde}}</td>
+        <td>{{zeile.start_soll}}<br/>{{zeile.start}}</td>
+        <td>{{zeile.ende_soll}}<br/>{{zeile.ende}}</td>
+        <td>{{minuten(zeile.abweichung)}}</td>
+        <td><a data-toggle="modal" data-target="#fehler-modal" ng-click="setCurrent(zeile)"><span class="label label-danger label-{{zeile.anzahl}}">{{zeile.anzahl}}</span></a>
+            <button type="button" class="btn btn-default btn-sm" ng-show="zeile.bearbeitet != '0'" data-toggle="tooltip" data-placement="top" title="{{zeile.kommentar}}">
+                <span class="glyphicon" ng-class="{'glyphicon-ok':zeile.kommentar=='', 'glyphicon-comment':zeile.kommentar!=''&&zeile.kommentar!=null, 'glyphicon-question-sign':zeile.kommentar==null}"></span> {{zeile.benutzer}}
+            </button>
+        </td>
+    </tr>
+</table>
+
+
+<!-- Modal -->
+<div class="modal fade" id="fehler-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
+                <h4 class="modal-title" id="myModalLabel">Fehlerbericht {{current.kunde}} - {{current.datum}}</h4>
+            </div>
+            <div class="modal-body">
+                <pre>
+                    {{current.fehler.logdatei}}
+                </pre>
+
+                <div class="logdatei" ng-repeat="e in current.fehler.fehlerbericht">
+                    <p class="modell" ng-class="{'rot':e.Errors.length > 0}">{{e.Type}}: {{e.Name}}</p>
+                    <p class="dateiname">
+                        Dateiname: {{e.Filename}}<br />
+                        Stand: {{dateFormat(e.Modified)}} ({{e.LastChangedDays}} Tage)
+                    </p>
 
+                    <div ng-show="e.Errors.length > 0">
 
+                        <ul class="fehler" ng-show="e.Type=='Modell'">
+                            <li ng-repeat="error in e.Errors"><a href="http://wiki.global-cube.de/{{error.Number}}">{{error.Number}}</a>:
+                                ({{error.Level}}) {{error.Message}}</li>
+                        </ul>
+                        <ul class="fehler" ng-show="e.Type=='WebCreator'">
+                            <li ng-repeat="error in e.Errors"><a href="http://wiki.global-cube.de/{{error.Number}}">{{error.Number}}</a>:
+                                ({{error.Level}}) {{error.Message}}</li>
+                        </ul>
+                        <table class="ft" ng-show="e.Type=='Portal'||e.Type=='Versand'">
+                            <tbody ng-repeat="error in e.Errors">
+                                <tr>
+                                    <td rowspan="5" class="number">{{$index+1}}
+                                    <td>Datei:</td>
+                                    <td>{{error.Filename}}</td>
+                                </tr>
+                                <tr>
+                                    <td>Stand:</td>
+                                    <td>{{error.Modified}}</td>
+                                </tr>
+                                <tr>
+                                    <td>Benutzer:</td>
+                                    <td>{{error.User}}</td>
+                                </tr>
+                                <tr>
+                                    <td>Bericht:</td>
+                                    <td>{{error.Report}} (Schicht {{error.Layer}})</td>
+                                </tr>
+                                <tr class="strich">
+                                    <td>Empfänger:</td>
+                                    <td>{{error.MailTo}}</td>
+                                </tr>
+                            </tbody>
+                        </table>
+
+                    </div>
+                </div>
+
+
+                <table class="table table-hover table-bordered">
+                    <tr>
+                        <th>Benutzer</th>
+                        <td>
+                            <input type="text" ng-model="current.fehler.benutzer" />
+                        </td>
+                    </tr>
+                    <tr>
+                        <th>Kommentar</th>
+                        <td>
+                            <label>
+                                <textarea cols="40" rows="5">{{current.fehler.kommentar}}</textarea>
+                            </label>
+                        </td>
+                    </tr>
+                    <tr>
+                        <th>Anzahl Fehler</th>
+                        <td>
+                            <label>
+                                <input type="text" ng-model="current.fehler.anzahl"/>
+                            </label>
+                        </td>
+                    </tr>
+                    <tr>
+                        <th>Bearbeitungsstand</th>
+                        <td>
+                            <label>
+                                <select ng-model="current.fehler.bearbeitet" ng-options=""></select>
+                            </label>
+                        </td>
+                    </tr>
+                </table>
+
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-primary" ng-click="saveComments()">Speichern</button>
+            </div>
+        </div>
+    </div>
 </div>
+
+
+<style>
+.table tbody tr td {
+    vertical-align: middle;
+}
+
+.label-0 {
+    background-color: #aaaaaa;
+}
+
+.label-1 {
+    background-color: #bbbb00;
+}
+
+.label-2 {
+    background-color: #bb8800;
+}
+
+.label-3 {
+    background-color: #bb0000;
+}
+
+.label-O {
+    background-color: #888888;
+}
+
+.label-E {
+    background-color: #338833;
+}
+
+.label-G {
+    background-color: #5577cc;
+}
+
+.label-B {
+    background-color: #0022bb;
+}
+
+.label-A {
+    background-color: #dddd22;
+    color: #000000;
+}
+
+
+
+
+table.ft {
+    border: 1px solid #888;
+}
+
+table.ft td {
+    padding: 3px 5px;
+    margin: 2px;
+    background-color: #ddd;
+}
+
+.logdatei {
+    margin: 10px 5px 20px 5px;
+    padding: 0 20px 10px 20px;
+    background-color: #eee;
+    border: 1px solid #888;
+}
+
+.modell {
+    font-weight: bold;
+    background-color: #ccc;
+    padding: 10px;
+    margin: 0 -20px;
+}
+
+.rot {
+    background-color: #e88;
+}
+
+.number {
+    font-weight: bold;
+    background-color: #ccc;
+    border: 1px solid #888888;
+}
+
+.strich {
+    border-bottom: 1px solid #888888;
+}
+
+</style>