Jump to content

Admin Blend Product/Configurable options editing mini calculator


ServerAstra

Recommended Posts

It's simple code which will make you editing your prices a breeze. It's not excel but it's nice to have this. Especially with no ability to automate it in default whmcs (:( which is a shame really).

 

I will add some modifications later (we definitely need a modifier for automation to change price accordingly) if someone will like this and request it.

 

It evaluates simple js math and has modifiers c to copy over row and a to copy with automatic division by months.

 

Changes to rows or cells are applied on focus loss of the price input box.

 

 

Edit /admin/templates/blend/head.js

Insert After

   $(".datepick, .date-picker").datepicker({
       dateFormat: datepickerformat,
       showOn: "button",
       buttonImage: "images/showcalendar.gif",
       buttonImageOnly: true,
       showButtonPanel: true,
       showOtherMonths: true,
       selectOtherMonths: true
   });

Code itself

   var getKeyByValue = function( object, value ) {
       for( var prop in object ) {
           if( object.hasOwnProperty( prop ) ) {
                if( object[ prop ] === value )
                    return prop;
           }
       }
   }
   if (window.location.href.indexOf('/configproducts.php?action=edit&id=') != -1)
   {

       $('#pricingtbl input[name^="currency["]:text').on("focusout", function() {
           if (/[0-9\*\.\+\-\/\|]+[ca]?$/.test($(this).val()) == true)
           {
               if (/[ca]+$/.test($(this).val()) == true)
               {
                   var eee = $(this).val().match(/[ca]+$/)[0];
               }
               else
               {
                   var eee = '';
               }
               $(this).val((eval($(this).val().replace(/[ca]{0,2}$/,''))).toFixed(2)+eee);
           }
           if (/[ca]+$/.test($(this).val()) == true)
           {
               var setuparr = {1:'msetupfee',3:'qsetupfee',6:'ssetupfee',12:'ase  tupfee',24:'bsetupfee',36:'tsetupfee'};
               var pricearr = {1:'monthly',3:'quarterly',6:'semiannually',12:'an  nually',24:'biennially',36:'triennialy'};
               var currency = $(this).attr('name').split('[')[1].slice(0,-1);
               var order = $(this).attr('name').split('[')[2].slice(0,-1);
               var prevval = $(this).val().replace(/[ca]+$/,'');
               var automate = /a/.test($(this).val());
               if($.inArray(order,setuparr) > -1)
               {
                   var finalarr = setuparr;

               }
               else
               {
                   var finalarr = pricearr;
               }
               if (automate == true)
               {
                   prevval = eval(prevval + "/" + getKeyByValue(finalarr,order));
               }
               $.each(finalarr, function (i,v){
                   if (automate == true)
                   {
                       var finalval = eval(prevval + "*" + i);
                   }
                   else
                   {
                       var finalval = parseFloat(prevval);
                   }
                   $('#pricingtbl input[name="currency['+currency+']['+v+']"]:text').val(finalval.toFixed(2));
               });
           }
       });
   }
   if (window.location.href.indexOf('/configproductoptions.php?manageoptions=true&cid=') != -1)
   {

       $('input[name^="price["]:text').on("focusout", function() {
           if (/[0-9\*\.\+\-\/\|]+[ca]?$/.test($(this).val()) == true)
           {
               if (/[ca]+$/.test($(this).val()) == true)
               {
                   var eee = $(this).val().match(/[ca]+$/)[0];
               }
               else
               {
                   var eee = '';
               }
               $(this).val((eval($(this).val().replace(/[ca]{0,2}$/,''))).toFixed(2)+eee);
           }
           if (/[ca]+$/.test($(this).val()) == true)
           {
               var setuparr = {1:'1',3:'2',6:'3',12:'4',24:'5',36:'11'};
               var pricearr = {1:'6',3:'7',6:'8',12:'9',24:'10',36:'12'};
               var optiongroup = $(this).attr('name').split('[')[2].slice(0,-1);
               var currency = $(this).attr('name').split('[')[1].slice(0,-1);
               var order = $(this).attr('name').split('[')[3].slice(0,-1);
               var prevval = $(this).val().replace(/[ca]+$/,'');
               var automate = /a/.test($(this).val());
               if($.inArray(order,setuparr) > -1)
               {
                   var finalarr = setuparr;

               }
               else
               {
                   var finalarr = pricearr;
               }
               if (automate == true)
               {
                   prevval = eval(prevval + "/" + getKeyByValue(finalarr,order));
               }
               $.each(finalarr, function (i,v){
                   if (automate == true)
                   {
                       var finalval = eval(prevval + "*" + i);
                   }
                   else
                   {
                       var finalval = parseFloat(prevval);
                   }
                   $('input[name="price['+currency+']['+optiongroup+']['+v+']"]:text').val(finalval.toFixed(2));
               });
           }
       });
   }

Insert Before

   jQuery(".credit-card-type li a").click(function() {
       jQuery("#selectedCard").html(jQuery(this).html());
       jQuery("#cctype").val(jQuery('span.type', this).html());
   });

 

This code is brought to you by ServerAstra team and is a public domain property where applicable.

Link to comment
Share on other sites

  • 2 months later...

Updated version. There were problems at some pages, so here's the fix

 

var getKeyByValue = function( object, value ) {
       for( var prop in object ) {
           if( object.hasOwnProperty( prop ) ) {
                if( object[ prop ] === value )
                    return prop;
           }
       }
   }
   if (window.location.href.indexOf('/configproducts.php?action=edit&id=') != -1)
   {

       $('#pricingtbl input[name^="currency["]:text').on("focusout", function() {
           if (/[0-9\*\.\+\-\/\|]+[ca]?$/.test($(this).val()) == true)
           {
               if (/[ca]+$/.test($(this).val()) == true)
               {
                   var eee = $(this).val().match(/[ca]+$/)[0];
               }
               else
               {
                   var eee = '';
               }
               $(this).val((eval($(this).val().replace(/[ca]{0,2}$/,''))).toFixed(2)+eee);
           }
           if (/[ca]+$/.test($(this).val()) == true)
           {
               var setuparr = {1:'msetupfee',3:'qsetupfee',6:'ssetupfee',12:'asetupfee',24:'bsetupfee',36:'tsetupfee'};
               var pricearr = {1:'monthly',3:'quarterly',6:'semiannually',12:'annually',24:'biennially',36:'triennially'};
               var currency = $(this).attr('name').split('[')[1].slice(0,-1);
               var order = $(this).attr('name').split('[')[2].slice(0,-1);
               var prevval = $(this).val().replace(/[ca]+$/,'');
               var automate = /a/.test($(this).val());
               var setuparra = $.map(setuparr, function(el) { return el });
               if($.inArray(order,setuparra) !== -1)
               {
                   var finalarr = setuparr;

               }
               else
               {
                   var finalarr = pricearr;
               }
               if (automate == true)
               {
                   prevval = eval(prevval + "/" + getKeyByValue(finalarr,order));
               }
               $.each(finalarr, function (i,v){
                   if (automate == true)
                   {
                       var finalval = eval(prevval + "*" + i);
                   }
                   else
                   {
                       var finalval = parseFloat(prevval);
                   }
                   $('#pricingtbl input[name="currency['+currency+']['+v+']"]:text').val(finalval.toFixed(2));
               });
           }
       });
   }
   if (window.location.href.indexOf('/configproductoptions.php?manageoptions=true&cid=') != -1)
   {

       $('input[name^="price["]:text').on("focusout", function() {
           if (/[0-9\*\.\+\-\/\|]+[ca]?$/.test($(this).val()) == true)
           {
               if (/[ca]+$/.test($(this).val()) == true)
               {
                   var eee = $(this).val().match(/[ca]+$/)[0];
               }
               else
               {
                   var eee = '';
               }
               $(this).val((eval($(this).val().replace(/[ca]{0,2}$/,''))).toFixed(2)+eee);
           }
           if (/[ca]+$/.test($(this).val()) == true)
           {
               var setuparr = {1:'1',3:'2',6:'3',12:'4',24:'5',36:'11'};
               var pricearr = {1:'6',3:'7',6:'8',12:'9',24:'10',36:'12'};
               var optiongroup = $(this).attr('name').split('[')[2].slice(0,-1);
               var currency = $(this).attr('name').split('[')[1].slice(0,-1);
               var order = $(this).attr('name').split('[')[3].slice(0,-1);
               var prevval = $(this).val().replace(/[ca]+$/,'');
               var automate = /a/.test($(this).val());
               var setuparra = $.map(setuparr, function(el) { return el });
               if($.inArray(order,setuparra) > -1)
               {
                   var finalarr = setuparr;
               }
               else
               {
                   var finalarr = pricearr;
               }
               if (automate == true)
               {
                   prevval = eval(prevval + "/" + getKeyByValue(finalarr,order));
               }
               $.each(finalarr, function (i,v){
                   if (automate == true)
                   {
                       var finalval = eval(prevval + "*" + i);
                   }
                   else
                   {
                       var finalval = parseFloat(prevval);
                   }
                   $('input[name="price['+currency+']['+optiongroup+']['+v+']"]:text').val(finalval.toFixed(2));
               });
           }
       });
   }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated