0 Replies Latest reply on May 11, 2017 7:00 AM by Simon_SIFON

    Changing a calcutator Script

    Simon_SIFON Level 1

      Hello Everyone!

       

      I've found this script and it is really helpful!

      I still got a Problem. I want to put "h" instead of 0.00 for the first column.

      And like i don't know anything about scripting i'm a bit stuck.

      Any help would be super appreciated!

       

      Best,

      Simon

       

      Like my Table looks like:

      Bildschirmfoto 2017-05-11 um 15.55.44.png

       

      Like my Table should look like:

      Bildschirmfoto 2017-05-11 um 15.57.34.png

       

      and here is the Script:

       

      // simpleBilling.jsx   

        

      var MWST = 8/100;  

      if (app.selection[0].parent.constructor.name == "Cell"){   

          var myTable = app.selection[0].parent.parent;   

          var myLastCol = myTable.columns.length-1;   

          var myLastRow = myTable.rows.length-1;   

          var myStunden = myTable.columns.item(1).contents;

          var myNetto = myTable.columns.item(2).contents;

          var mySum = 0;   

          var myPrice = 0;

          for (k = 0; k < myLastRow-2; k++) {   

       

               myPrice = (((myTable.columns.item(1).cells[k].contents))*((myTable.columns.item(2).cells[k].content s)));

       

               myTable.columns.item(1).cells[k].contents = digitFormatter(myTable.columns.item(1).cells[k].contents);

               myTable.columns.item(2).cells[k].contents = digitFormatter(myTable.columns.item(2).cells[k].contents);

       

               myTable.columns[myLastCol].cells[k].contents  = digitFormatter(myPrice);   

               mySum += (myTable.columns[myLastCol].cells[k].contents.replace(",",  "."))*1   ;

       

          }   

          

          myTable.columns[myLastCol].cells[myLastRow-2].contents  = digitFormatter(mySum);   

          myTable.columns[myLastCol].cells[myLastRow-1].contents  = digitFormatter(mySum*MWST);   

          myTable.columns[myLastCol].cells[myLastRow].contents  = digitFormatter(mySum*MWST + mySum);   

      }  

       

       

      function digitFormatter(x) {  

          // Quelle: http://www.dcljs.de/faq/antwort.php?Antwort=rechnen_runden#6  

          var k = (Math.round(x * 100) / 100).toString();  

          k += (k.indexOf('.') == -1)? '.00' : '00';  

          var p = k.indexOf('.');  

          return k.substring(0, p) + ',' + k.substring(p+1, p+3);  

      }