Make Date Addition for Hold Receipt Configurable on Client feature/hold_slip_format_due_date
authorArt Rhyno <art632000@yahoo.ca>
Tue, 12 Feb 2013 16:25:08 +0000 (11:25 -0500)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 19:53:10 +0000 (15:53 -0400)
As per Dan Scott's suggestion, this changes the print_win.js
function for formatting the holds date receipt to allow
the number of days to be specified with the "add_days" attribute.

Signed-off-by: Art Rhyno <art632000@yahoo.ca>
Open-ILS/xul/staff_client/chrome/content/util/print_win.js

index 8faadf1..035692b 100644 (file)
@@ -9,7 +9,7 @@ function print_init(type) {
     if (typeof print_custom == "function") {
         print_custom(type);
     } else {
-        print_do_hold_dates(5);
+        print_do_hold_dates();
         print_do_sums();
         print_check_alt();
         print_check_noprint();
@@ -169,22 +169,26 @@ function print_do_sums() {
  * Use example:
  * <!-- blah blah -->
  * <!-- Probably as line_item entries: -->
- * <span hold_date="hold">Due Date: 5 days from Now</span>
+ * <span hold_date="today" add_days="5">Due Date: 5 days from Now</span>
  */
-function print_do_hold_dates(daysToAdd) {
-    var holdDate = new Date();
-    holdDate.setDate(holdDate.getDate() + daysToAdd); 
-    var d = holdDate.getDate();
-    var m = holdDate.getMonth()+1;
-    var y = holdDate.getFullYear();
-
-    var holdDue = 'Due Date: ' + y +'-'+ (m<=9?'0'+m:m) +'-'+ (d<=9?'0'+d:d);
+function print_do_hold_dates() {
     var spans = document.getElementsByTagName('span');
     if(!spans) return;
     for (var i = 0; i < spans.length; i++) {
-        var dateset = spans[i].getAttribute("hold_date");
-        if(dateset) {
-            spans[i].textContent = holdDue;
+        var hold_date = spans[i].getAttribute("hold_date");
+        var add_days = spans[i].getAttribute("add_days");
+        if(hold_date && add_days) {
+            var daysToAdd = parseInt(add_days);
+            if (daysToAdd > 0 && daysToAdd < 365) {
+                var holdDate = new Date();
+                holdDate.setDate(holdDate.getDate() + daysToAdd);
+                var d = holdDate.getDate();
+                var m = holdDate.getMonth()+1;
+                var y = holdDate.getFullYear();
+
+                var holdDue = 'Due Date: ' + y +'-'+ (m<=9?'0'+m:m) +'-'+ (d<=9?'0'+d:d);
+                spans[i].textContent = holdDue;
+             }//if daysToAdd
         }//if
     }//for
 }