From e753371bf139eef9c53b940cf1eab470a46ff385 Mon Sep 17 00:00:00 2001
From: wactbprot <thsteinbock@web.de>
Date: Fri, 10 Mar 2017 13:19:49 +0100
Subject: [PATCH] sort by KS No.

---
 README.md             |   6 +--
 lists/sum.js          |  21 +++++----
 templates/body.html   |  15 +++++--
 templates/header.html |  10 +++--
 views/all/map.js      | 102 ++++++++++++++++++++++--------------------
 5 files changed, 85 insertions(+), 69 deletions(-)

diff --git a/README.md b/README.md
index 0b8fd29..e5e9a4f 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,6 @@
 
 ## link
 
-* [2016](http://a73434.berlin.ptb.de:5984/vl_db/_design/az/_list/sum/all?key=%222016%22)
-* [2017](http://a73434.berlin.ptb.de:5984/vl_db/_design/az/_list/sum/all?key=%222017%22)
-* [2018](http://a73434.berlin.ptb.de:5984/vl_db/_design/az/_list/sum/all?key=%222018%22)
+* [2016](http://a73434.berlin.ptb.de:5984/vl_db/_design/az/_list/sum/all?startkey=%222016_75000%22&endkey=%222016_75999%22)
+* [2017](http://a73434.berlin.ptb.de:5984/vl_db/_design/az/_list/sum/all?startkey=%222017_75000%22&endkey=%222017_75999%22)
+* [2018](http://a73434.berlin.ptb.de:5984/vl_db/_design/az/_list/sum/all?startkey=%222018_75000%22&endkey=%222018_75999%22)
diff --git a/lists/sum.js b/lists/sum.js
index ef3f0af..d293c86 100644
--- a/lists/sum.js
+++ b/lists/sum.js
@@ -1,23 +1,22 @@
 function(head, req) {
 
   var mustache = require("lib/couchapp/mustache")
-    , share   = require("lib/vaclab/share")
-    , year    = req.query.key
-    , header  = this.templates.header
-    , body    = this.templates.body
-    , foot    = this.templates.foot
-    , row, i= 1, all     = {};
+    , share    = require("lib/vaclab/share")
+    , startyear = req.query.startkey.split("_")[0]
+    , endyear   = req.query.endkey.split("_")[0]
+    , header   = this.templates.header
+    , body     = this.templates.body
+    , foot     = this.templates.foot
+    , row, i= 1, all = {};
 
   start({headers: {"Content-type": "text/html; charset=utf-8"}});
 
-  send( mustache.to_html(header,
-                         {"Title":"Übersicht Aktenzeichen " + year }));
+  var titleadd = startyear == endyear ? startyear : startyear + " bis " + endyear
+  send( mustache.to_html(header, {"Title":"Übersicht Aktenzeichen " +  titleadd   }));
 
   while(row = getRow()) {
     var rv = row.value,
-        ak = rv.Certificate + rv.Year
-
-
+        ak = rv.Certificate + rv.Year;
 
     if(rv.CustomerSign){
       rv.CustomerDocId = "cus-" + rv.CustomerSign.toLowerCase();
diff --git a/templates/body.html b/templates/body.html
index 432d27a..7900fe9 100644
--- a/templates/body.html
+++ b/templates/body.html
@@ -59,11 +59,20 @@
   <td class="no_{{Number}}" title="Datum Ks" data-row="{{Number}}">
     {{DateCertificate}}
   </td>
+  
+  <td class="no_{{Number}}" title="Fakturaanforderung" data-row="{{Number}}">
+    {{Fakturaanforderung}}
+  </td>
+  
+  <td class="no_{{Number}}" title="" data-row="{{Number}}">
+    {{Faktura}}
+  </td>
 
-  <td class="no_{{Number}}" title="Gerätename" data-row="{{Number}}">
-    {{DeviceName}}
+  <td class="no_{{Number}} {{DateTerminated}}" title="technisch abgeschlossen" data-row="{{Number}}">
+    {{DateTerminated}}
   </td>
-  <td class="no_{{Number}}" title="Gerätetyp" data-row="{{Number}}">
+
+  <td class="no_{{Number}}" title="Gegenstand" data-row="{{Number}}">
     {{DeviceType}}
   </td>
   <td class="no_{{Number}}" title="Kalibrierziel" data-row="{{Number}}">
diff --git a/templates/header.html b/templates/header.html
index bdd7263..8260949 100644
--- a/templates/header.html
+++ b/templates/header.html
@@ -26,7 +26,8 @@
       .missing { color:black; background-color: #EDE15C; }
       .info    { color:black;background-color: #CEED5C; }
       .selected { color:black; background-color: #EBFAF3; }
-
+      .waiting {color:black;background-color: #ECE8FA; }
+      
       overflow: scroll; /* Scrollbar are always visible */
       overflow: auto;   /* Scrollbar is displayed as it's needed */
     </style>
@@ -60,9 +61,12 @@
         <th>Solltermin</th>
         <th>Start Messung</th>
         <th>Datum KS</th>
+	
+	<th>Fakturaanforderung </th>
+	<th>Faktura</th>
+	<th>tech. abgeschl.</th>
 
-        <th>Gerät</th>
-        <th>Gerätetyp</th>
+        <th>Gegenstand</th>
         <th>Kalibrierziel</th>
         <th>Standard</th>
         <th>Messbeauftragter</th>
diff --git a/views/all/map.js b/views/all/map.js
index ea4275b..3d589f5 100644
--- a/views/all/map.js
+++ b/views/all/map.js
@@ -5,64 +5,68 @@ function(doc) {
     if(dc.Titlepage){
       var dct = dc.Titlepage;
 
-      emit(dct.FullYear, {Certificate: dct.Certificate,
+      emit(dct.FullYear + "_" + dct.Certificate, {Certificate: dct.Certificate,
                           Year:dct.FullYear,
                           DateCertificate: dct.CertificateDate});
     }
   }
 
-    if(doc.Calibration && doc.Calibration.Type == "KK"){
-      var dc     = doc.Calibration
-        , dct    = dc.ToDo
-        , pcp    = dc.Presettings
-        , pcm    = dc.Measurement
-        , pca    = dc.Analysis
-        , dcc    = dc.Customer
-        , cdcuco = dc.CustomerObject
-        , PresDate = {}
-        , MeasDate = ""
-        , AnDate   = ""
-        , missing  = "missing"
-        , none     = "none"
+  if(doc.Calibration && doc.Calibration.Type == "KK"){
+    var dc     = doc.Calibration
+      , dct    = dc.ToDo
+      , pcp    = dc.Presettings
+      , pcm    = dc.Measurement
+      , pca    = dc.Analysis
+      , dcc    = dc.Customer
+      , cdcuco = dc.CustomerObject
+      , PresDate = {}
+      , MeasDate = ""
+      , AnDate   = ""
+      , missing  = "missing"
+      , none     = "none"
+      , waiting  = "waiting"
 
-      if(pcp && pcp.Date){
-        for(var i = 0; i <   pcp.Date.length; i++){
-          PresDate[pcp.Date[i].Type] = pcp.Date[i].Value
-        }
+    if(pcp && pcp.Date){
+      for(var i = 0; i <   pcp.Date.length; i++){
+        PresDate[pcp.Date[i].Type] = pcp.Date[i].Value
       }
+    }
 
-      if(pcm && pcm.Date){
-        for(var i = 0; i < pcm.Date.length; i++){
-          MeasDate = pcm.Date[i].Value[0] ? pcm.Date[i].Value[0] : pcm.Date[i].Value
-        }
+    if(pcm && pcm.Date){
+      for(var i = 0; i < pcm.Date.length; i++){
+        MeasDate = pcm.Date[i].Value[0] ? pcm.Date[i].Value[0] : pcm.Date[i].Value
       }
+    }
 
 
-      emit(dc.Year, {id: doc._id,
-                     Year:dc.Year,
-                     Certificate:dc.Certificate,
-                     CustomerName :dcc.Name,
-                     CustomerSign :dcc.Sign,
-                     CustomerComment: dcc.Comment,
-                     DebitorenNr : dcc.DebitorenNr,
-                     CustomerType: dcc.Type,
-                     ContactName: dcc.Contact.Name,
-                     ContactEmail: dcc.Contact.Email,
-                     ContactPhone: dcc.Contact.Phone,
-                     DateGen: PresDate["generated"] ? PresDate["generated"] : missing,
-                     DateCust: PresDate["CustomerRef"] ? PresDate["CustomerRef"]: missing,
-                     DateSchedule: PresDate["schedule"] ? PresDate["schedule"] : missing,
-                     DateMeas: MeasDate ? MeasDate : "",
-                     SAP: pcp.SAPNo ?  pcp.SAPNo: missing,
-                     ReferenceNo: pcp.ReferenceNo,
-                     CustomerReference: pcp.CustomerSign.length < 2 ? none : pcp.CustomerSign,
-                     DeviceName: cdcuco.Name,
-                     DeviceType: cdcuco.Type,
-                     ToDoName:dct.Name,
-                     Standard:dct.Standard,
-                     Fee: dct.Fee ,
-                     MeasMaintainer:pcm.Maintainer
-
-                    });
-    }
+    emit(  dc.Year+ "_" + dc.Certificate,
+         {id: doc._id,
+          Year:dc.Year,
+          Certificate:dc.Certificate,
+          CustomerName :dcc.Name,
+          CustomerSign :dcc.Sign,
+          CustomerComment: dcc.Comment,
+          DebitorenNr : dcc.DebitorenNr,
+          CustomerType: dcc.Type,
+          ContactName: dcc.Contact.Name,
+          ContactEmail: dcc.Contact.Email,
+          ContactPhone: dcc.Contact.Phone,
+          DateGen: PresDate["generated"] ? PresDate["generated"].split(" ")[0] : missing,
+          DateCust: PresDate["CustomerRef"] ? PresDate["CustomerRef"]: missing,
+          DateSchedule: PresDate["schedule"] ? PresDate["schedule"] : missing,
+          DateTerminated: PresDate["terminated"] ? PresDate["terminated"] : waiting,
+          DateMeas: MeasDate ? MeasDate.split(" ")[0]  : "",
+          SAP: pcp.SAPNo ?  pcp.SAPNo: missing,
+          ReferenceNo: pcp.ReferenceNo,
+          Fakturaanforderung : pcp.Fakturaanforderung ,
+          Faktura: pcp.Faktura ,
+          CustomerReference: pcp.CustomerSign.length < 2 ? none : pcp.CustomerSign,
+          DeviceName: cdcuco.Name,
+          DeviceType: cdcuco.Type,
+          ToDoName:dct.Name,
+          Standard:dct.Standard,
+          Fee: dct.Fee ,
+          MeasMaintainer:pcm.Maintainer
+         });
+  }
 }
-- 
GitLab