Merge remote branch 'kc/new/bug_5446' into kcmaster
[koha_fer] / koha-tmpl / intranet-tmpl / prog / en / js / acq.js
index dce702b..326062d 100644 (file)
@@ -50,104 +50,11 @@ function isNum(v,maybenull) {
     if (maybenull==0 && v.value=='') {
 
 
-     return false;
+    return false;
     }
     return true;
 }
 
-// this function checks if date is like DD/MM/YYYY
-function CheckDate(field) {
-    var d = field.value;
-    if (d!="") {
-        var amin = 1900;
-        var amax = 2100;
-        var date = d.split("/");
-        var ok=1;
-        var msg;
-        if ( (date.length < 2) && (ok==1) ) {
-            msg = _("Separator must be /");
-                alert(msg); ok=0; field.focus();
-                return false;
-        }
-        var dd   = date[0];
-        var mm   = date[1];
-        var yyyy = date[2];
-        // checking days
-        if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
-            msg = _("day not correct.");
-            alert(msg); ok=0; field.focus();
-            return false;
-        }
-        // checking months
-        if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
-            msg = _("month not correct.");
-            alert(msg); ok=0; field.focus();
-            return false;
-        }
-        // checking years
-        if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
-            msg = _("years not correct.");
-            alert(msg); ok=0; field.focus();
-            return false;
-        }
-        // check day/month combination
-        if ((mm==4 || mm==6 || mm==9 || mm==11) && dd==31) {
-            msg = _("Invalid Day/Month combination. Please ensure that    you have a valid day/month combination.");
-            alert(msg); ok=0; field.focus();
-            return false;
-        }
-        // check for february 29th
-        if (mm == 2) {
-            var isleap = (yyyy % 4 == 0 && (yyyy % 100 != 0 || yyyy %    400 == 0));
-            if (dd>29 || (dd==29 && !isleap)) {
-                msg = _("Invalid Day. This year is not a leap year.       Please enter a value less than 29 for the day.");
-                alert(msg); ok=0; field.focus();
-                return false
-            }
-        }
-    }
-    return true;
-}
-
-// Checks wether start date is greater than end date
-function CompareDate(startdate, enddate) {
-    startdate=startdate.split("/");
-    syear = startdate[2];
-    smonth = startdate[1];
-    sday = startdate[0];
-    enddate=enddate.split("/");
-    eyear = enddate[2];
-    emonth = enddate[1];
-    eday = enddate[0];
-
-    var sdate = new Date(syear,smonth-1,sday);
-    var edate = new Date(eyear,emonth-1,eday);
-    if (sdate > edate) {
-        msg = _("Start date after end date, please check the dates!");
-        alert(msg); ok=0; field.focus();
-        return false;
-    }
-    return true;
-}
-
-// checks wether end date is before today, returns false if it is
-function CheckEndDate(enddate) {
-    enddate=enddate.split("/");
-    eyear = enddate[2];
-    emonth = enddate[1];
-    eday = enddate[0];
-    var edate = new Date(eyear,emonth-1,eday);
-    var today = new Date( );
-    if (today > edate) {
-        msg = _("End date before today, Invalid end date!");
-        alert(msg); ok=0; field.focus();
-        return false;
-    }
-    return true;
-}
-
-
-
 //=======================================================================
 
 //=======================================================================
@@ -417,7 +324,7 @@ function enterpressed(event){
 
     if (keycode == 13)
     {
-         return true;
+        return true;
     }
     else return false;
 }
@@ -473,6 +380,14 @@ function closebasketgroup(bgid) {
     div.appendChild(unclosegroup);
 }
 
+function closeandprint(bg){
+       if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&amp;basketgroupid=' + bg ){
+               setTimeout("window.location.reload();",3000);
+       }else{
+               alert('Error downloading the file');
+       }
+}
+
 //function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page.
 function unclosegroup(bgid){
     var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode;
@@ -603,12 +518,12 @@ function rename(event, bgid, name){
 function log(message) {
     if (!log.window_ || log.window_.closed) {
         var win = window.open("", null, "width=400,height=200," +
-                              "scrollbars=yes,resizable=yes,status=no," +
-                              "location=no,menubar=no,toolbar=no");
+                            "scrollbars=yes,resizable=yes,status=no," +
+                            "location=no,menubar=no,toolbar=no");
         if (!win) return;
         var doc = win.document;
         doc.write("<html><head><title>Debug Log</title></head>" +
-                  "<body></body></html>");
+                "<body></body></html>");
         doc.close();
         log.window_ = win;
     }
@@ -621,7 +536,7 @@ function log(message) {
 
 
     function ownerPopup(f) {
-      window.open("/cgi-bin/koha/admin/aqbudget_owner_search.pl?op=budget",'PatronPopup','width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+    window.open("/cgi-bin/koha/admin/aqbudget_owner_search.pl?op=budget",'PatronPopup','width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
     }
         //
 //=======================================================================
@@ -644,7 +559,7 @@ function calcTotalRow(cell) {
 
     var bud_id =  cell.className;
     var val1 =    cell.value;
-    var remainingTotal =   document.getElementById("budget_est_"+bud_id) ;
+    var remainingTotal =   document.getElementById("budget_est_"+bud_id).textContent;
     var remainingNew =0;
     var budgetTotal  =  document.getElementById("budget_tot_"+bud_id ).textContent;
     var arr =  getElementsByClass(bud_id);
@@ -669,7 +584,7 @@ function calcTotalRow(cell) {
         remainingTotal.style.color = 'black';
     }
     else if ( remainingNew   > 0   )       {
-         remainingTotal.style.color = 'green';
+        remainingTotal.style.color = 'green';
     } else  {    // if its negative, make it red..
         remainingTotal.style.color = 'red';
     }
@@ -679,10 +594,10 @@ function calcTotalRow(cell) {
 
 function autoFillRow(bud_id) {
 
-    var remainingTotal =   document.getElementById("budget_est_"+bud_id) ;
+    var remainingTotal =   document.getElementById("budget_est_"+bud_id).textContent;
     var remainingNew = new Number;
     var budgetTotal  =  document.getElementById("budget_tot_"+bud_id ).textContent;
-    var arr =  getElementsByClass(bud_id);
+    var arr =  getElementsByClass("plan_entry_" + bud_id);
 
     budgetTotal   =  budgetTotal.replace(/\,/, "");
     var qty = new Number;
@@ -724,74 +639,93 @@ function messenger(X,Y,etc){    // FIXME: unused?
 
 //  NEXT BLOCK IS USED BY NEWORDERBEMPTY
 
-function calcNeworderTotal(f){
-       //collect values
-       var quantity = new Number(f.quantity.value);
-       var discount = new Number(f.discount.value);
-       var listinc  = new Number (f.listinc.value);
-       var currency = f.currency.value;
-       var applygst = new Number (f.applygst.value);
-       var list_price   =  new Number(f.list_price.value);
-       var invoiceingst =  new Number (f.invoiceincgst.value);
-       var exchangerate =  new Number(f.elements[currency].value);      //get exchange rate
-       var gst_on=(!listinc && invoiceingst);
-
-       //do real stuff
-       var rrp   = new Number(list_price*exchangerate);
-       var ecost = new Number(rrp * (100 - discount ) / 100);
-       var GST   = new Number(0);
-       if (gst_on) {
-           rrp=rrp * (1+f.gstrate.value / 100);
-           GST=ecost * f.gstrate.value / 100;
-       }
+function calcNeworderTotal(){
+    //collect values
+    var f        = document.getElementById('Aform');
+    var quantity = new Number(f.quantity.value);
+    var discount = new Number(f.discount.value);
+    var listinc  = new Number (f.listinc.value);
+    var currency = f.currency.value;
+    var applygst = new Number (f.applygst.value);
+    var listprice   =  new Number(f.listprice.value);
+    var invoiceingst =  new Number (f.invoiceincgst.value);
+    var exchangerate =  new Number(f.elements[currency].value);      //get exchange rate
+    var gst_on=(!listinc && invoiceingst);
+
+    //do real stuff
+    var rrp   = new Number(listprice*exchangerate);
+    var ecost = new Number(rrp * (100 - discount ) / 100);
+    var GST   = new Number(0);
+    if (gst_on) {
+            rrp=rrp * (1+f.gstrate.value / 100);
+        GST=ecost * f.gstrate.value / 100;
+    }
 
-       var total =  new Number( (ecost + GST) * quantity);
+    var total =  new Number( (ecost + GST) * quantity);
 
-       f.rrp.value = rrp.toFixed(2);
+    f.rrp.value = rrp.toFixed(2);
 
 //     f.rrp.value = rrp
 //     f.rrp.value = 'moo'
 
-       f.ecost.value = ecost.toFixed(2);
-       f.total.value = total.toFixed(2);
-       f.list_price.value =  list_price.toFixed(2);
+    f.ecost.value = ecost.toFixed(2);
+    f.total.value = total.toFixed(2);
+    f.listprice.value =  listprice.toFixed(2);
 
 //  gst-stuff needs verifing, mason.
-       if (f.GST) {
-               f.GST.value=GST;
+    if (f.GST) {
+        f.GST.value=GST;
     }
-       return true;
+    return true;
+}
+
+// Calculates total amount in a suggestion
+
+function calcNewsuggTotal(){
+    //collect values
+    var quantity = new Number(document.getElementById('quantity').value);
+//    var currency = f.currency.value;
+    var currcode = new String(document.getElementById('currency').value);
+    var price   =  new Number(document.getElementById('price').value);
+    var exchangerate =  new Number(document.getElementById(currcode).value);
+
+    var total =  new Number(quantity*price*exchangerate);
+
+    document.getElementById('total').value = total.toFixed(2);
+    document.getElementById('price').value =  listprice.toFixed(2);
+    return true;
 }
 
+
 // ----------------------------------------
 //USED BY NEWORDEREMPTY.PL
 /*
 function fetchSortDropbox(f) {
-       var  budgetId=f.budget_id.value;
-       var handleSuccess = function(o){
-       if(o.responseText !== undefined){
-           sort_dropbox.innerHTML   = o.responseText;
-           }
-       }
+    var  budgetId=f.budget_id.value;
+    var handleSuccess = function(o){
+        if(o.responseText !== undefined){
+            sort_dropbox.innerHTML   = o.responseText;
+        }
+    }
 
-       var callback = {   success:handleSuccess };
+    var callback = {   success:handleSuccess };
     var sUrl = '../acqui/fetch_sort_dropbox.pl?sort=1&budget_id='+budgetId
     var sort_dropbox = document.getElementById('sort1');
     var request1 = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
-       var rr = '00';
+    var rr = '00';
 
 // FIXME: ---------  twice , coz the 2 requests get mixed up otherwise
 
-       var handleSuccess2 = function(o){
+    var handleSuccess2 = function(o){
     if(o.responseText !== undefined){
         sort2_dropbox.innerHTML   = o.responseText;
-       }
-       }
+        }
+    }
 
-       var callback2 = {   success:handleSuccess };
-       var sUrl2 = '../acqui/fetch_sort_dropbox.pl?sort=2&budget_id='+budgetId;
-       var sort2_dropbox = document.getElementById('sort2');
-       var request2 = YAHOO.util.Connect.asyncRequest('GET', sUrl2, callback2);
+    var callback2 = {   success:handleSuccess };
+    var sUrl2 = '../acqui/fetch_sort_dropbox.pl?sort=2&budget_id='+budgetId;
+    var sort2_dropbox = document.getElementById('sort2');
+    var request2 = YAHOO.util.Connect.asyncRequest('GET', sUrl2, callback2);
 
 }
 */
@@ -802,7 +736,7 @@ function fetchSortDropbox(f) {
 function fetchSortDropbox(f) {
     var  budgetId=f.budget_id.value;
 
- for (i=1;i<=2;i++) {
+for (i=1;i<=2;i++) {
 
     var sort_dropbox = document.getElementById('sort'+i);
     var url = '../acqui/fetch_sort_dropbox.pl?sort='+i+'&budget_id='+budgetId;
@@ -818,14 +752,14 @@ function fetchSortDropbox(f) {
 
     xmlhttp.onreadystatechange = function() {
         if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
-      // stupid JS...
-          } else {
-      // wait for the call to complete
-          }
-     };
-     // rc =  eval ( xmlhttp.responseText );
+    // stupid JS...
+        } else {
+    // wait for the call to complete
+        }
+    };
+    // rc =  eval ( xmlhttp.responseText );
     sort_dropbox.innerHTML  =  xmlhttp.responseText;
- }
+}
 }
 
 
@@ -852,12 +786,12 @@ function totalExceedsBudget(budgetId, total) {
 
             actTotal = eval ( xmlhttp.responseText );
 
-               if (  Math.abs(actTotal) < Math.abs(total)  ) {
-               // if budget is to low :(
-                   return true ;
-           } else {
-                   return false;
-           }
+            if (  Math.abs(actTotal) < Math.abs(total)  ) {
+            // if budget is to low :(
+                return true ;
+            } else {
+                return false;
+            }
         }
     }
 }
@@ -887,22 +821,22 @@ if ( newBudgetParent  ) { url +=  '&parent_id=' + newBudgetParent};
     xmlhttp.send(null);
 
     xmlhttp.onreadystatechange = function() {
-          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
-      // stupid JS...
-          } else {
-      // wait for the call to complete
-          }
-     };
+        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+    // stupid JS...
+        } else {
+    // wait for the call to complete
+        }
+    };
 
     var result = eval ( xmlhttp.responseText );
 
-     if (result == '1') {
+    if (result == '1') {
             return _("- Budget total exceeds parent allocation\n");
-     } else if (result == '2') {
+    } else if (result == '2') {
             return _("- Budget total exceeds period allocation\n");
-     } else  {
-             return false;
-     }
+    } else  {
+            return false;
+    }
 }
 
 
@@ -921,22 +855,22 @@ function checkBudgetParent(budgetId, newBudgetParent) {
     xmlhttp.send(null);
 
     xmlhttp.onreadystatechange = function() {
-          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
-      // do something with the results
-          } else {
-      // wait for the call to complete
-          }
-     };
+        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+    // do something with the results
+        } else {
+    // wait for the call to complete
+        }
+    };
 
-     var result = eval ( xmlhttp.responseText );
+    var result = eval ( xmlhttp.responseText );
 
-     if (result == '1') {
+    if (result == '1') {
             return _("- New budget-parent is beneath budget\n");
 //     } else if (result == '2') {
 //            return "- New budget-parent has insufficent funds\n";
 //     } else  {
 //              return false;
-     }
+    }
 }